bmjk
asked on
Search and Delete 0 byte Files in subdirectories
Im new to C. I need code to delete 0 byte files from the current directory, and if an argument is given, any subdirectories of the directory the executable is in also. I need this to work on DOS and Windows. It will do more than this, but thats the part im stuck on. Im using lcc-win32 as my compiler. Whats the easiest way to do this?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
To get you started:
Use the remove() function from stdio.h to delete a file.
int res;
res=remove("filename.txt") ;
On success,remove() returns 0.On error it returns -1.
For stat,you need sys/stat.h,Check up on your compiler though.
for findfirst(),findnext(),you need to include dos.h or dir.h on Borland Compilers.
On VC++,you need windows.h
To get you started:
Use the remove() function from stdio.h to delete a file.
int res;
res=remove("filename.txt")
On success,remove() returns 0.On error it returns -1.
For stat,you need sys/stat.h,Check up on your compiler though.
for findfirst(),findnext(),you
On VC++,you need windows.h
ASKER
I wish this was homework....at least then I'd have a book to fall back on. I just cant do it in vb because I need it on a DOS machine, and I have a C compiler. That was a lot of help, I just have 2 more questions about it.
1. can you explain this: (ffblk->st_mode & S_IFDIR)
2. I assume I can find the length in this ffblk. I'll look around for that. How do I delete the file? I found a remove() function somewhere. Will that work with this? Is there something easier to use for example something that would use that handle from findfirst()?
Otherwise, I think this gives me enough to figure it out. The biggest problem I was having was not knowing the header files... If you dont know those, its hard to figure out what functions do what you need.
Thanks...
Bryan
1. can you explain this: (ffblk->st_mode & S_IFDIR)
2. I assume I can find the length in this ffblk. I'll look around for that. How do I delete the file? I found a remove() function somewhere. Will that work with this? Is there something easier to use for example something that would use that handle from findfirst()?
Otherwise, I think this gives me enough to figure it out. The biggest problem I was having was not knowing the header files... If you dont know those, its hard to figure out what functions do what you need.
Thanks...
Bryan
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That sounds good in concept, but I'm really lost on the C stuff... what header files do i need for this? I dont even know how to delete a file in C. All I know is the basic systax. I mainly code in VB. I could write the this no problem in that langauge, but I need it in C.