How to delete files in a sub directory

Z

zhiwei wang

I am new to dealing with the file system using C. And couldnt find
anyone in my office to help me out. :(

okay here is my questions.

If I want to delete a file in a directory other than my working
directory, I would construct a string look like this:
str="../../foo/bar/foobar"
add use "remove(str);" to delete this file. A lot of my work involves
constructing the directory string, so I wonder if this is a common
practice of deleting files in C. Do you guys have better ways of
performing this task?

Thank you.
 
M

Mike Wahler

zhiwei wang said:
I am new to dealing with the file system using C. And couldnt find
anyone in my office to help me out. :(

okay here is my questions.

If I want to delete a file in a directory other than my working
directory, I would construct a string look like this:
str="../../foo/bar/foobar"
add use "remove(str);" to delete this file. A lot of my work involves
constructing the directory string, so I wonder if this is a common
practice of deleting files in C. Do you guys have better ways of
performing this task?

That's the only way to do it with standard C.
You could check your implementation's documentation to
see if it offers nonstandard exensions for working with
directories, if that would make things simpler for you.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top