Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 22nd, 2006, 3:01 AM   #1
myName
Programmer
 
Join Date: Oct 2005
Posts: 48
Rep Power: 0 myName is on a distinguished road
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??
myName is offline   Reply With Quote
Old Jun 22nd, 2006, 3:17 AM   #2
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
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
uman is offline   Reply With Quote
Old Jun 22nd, 2006, 3:28 AM   #3
myName
Programmer
 
Join Date: Oct 2005
Posts: 48
Rep Power: 0 myName is on a distinguished road
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 :-)
myName is offline   Reply With Quote
Old Jun 22nd, 2006, 3:39 AM   #4
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Jun 22nd, 2006, 3:47 AM   #5
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
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.
Jimbo is offline   Reply With Quote
Old Jun 22nd, 2006, 6:33 AM   #6
v0id
Hobbyist Programmer
 
Join Date: Apr 2006
Posts: 155
Rep Power: 3 v0id is on a distinguished road
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...'
v0id is offline   Reply With Quote
Old Jun 22nd, 2006, 9:58 AM   #7
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
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 .
Game_Ender is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC