![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 48
Rep Power: 0
![]() |
code check whether a folder is empty
Hello world,
Is there anywhere for C++ to check whether a folder is empty? Eg: A folder, with a name called "UploadFile". Inside the folder will be contain many text file with different file name like "20060302.txt, 20060303.txt....." The program logic is 1. Check whether the "UploadFile" folder is empty? 2. Get all the text file name inside the "UploadFile" folder. 3. Delete the text file. I was wondering is there anywhere to check whether the "UploadFile" folder is empty and how to get the file name inside the folder?? |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
it depends on the operating system.
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials. --WilliamSChips on Slashdot |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Oct 2005
Posts: 48
Rep Power: 0
![]() |
let say, the operating system allowed the logic..
How to code it in C++? i have no idea about it... i still searching on the net for some example.. if there anyone can give some guide, there be much appreciate :-) |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
You have to set the current directory, get the first file, if that fails there are no files.
Check to see if it is a text file, if so delete it. Check if there are other files, if so, then check to see if they are text files, if so delete them.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#5 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
If you're on Windows, I'm pretty sure that .NET has some pretty good support for the filesystem. If you're on a *nix platform, well, I don't rightly know what they've got. Surely something. You could also consider just using a shell script at that point though.
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 155
Rep Power: 3
![]() |
Try take a look at this: http://home20.inet.tele.dk/midgaard/snip/listfiles.html
It listing all files in a given directory, then you can try to combine it with 'if the list is empty then...' |
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
You can also check out the boost filesystem library. Boost can be hard to understand because of its heavy use of templates and the STL, but is_empty is the function you want.
Also the above example probably won't compile on windows under any VS compiler. See his explanation here . |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|