Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

How to check multilevel folders mean to say I will have one directory path and I go to that path and remove all the files in all folder... That may contains sub folder and with in that again sub folders. So I am not getting how to do that...

We have some period to keep the files. I have to remove the file only after checking the file created on versus given period. Once that period is over then only I can delete the file.

Can you please give an idea how to do that...

Thanks in advance.

Regards,
Naveen
Posted
Updated 24-Jul-14 22:15pm
v4

1 solution

Directory.Delete[^] has an overload which takes a bool value: when true, all files and sub folders are automatically removed.
 
Share this answer
 
Comments
NaVeN Kumar 25-Jul-14 4:12am    
We have some period to keep the files. I have to remove the file only after checking the file created on versus given period. Once that period is over then only I can delete the file.

Sorry I did not mention this before.
OriginalGriff 25-Jul-14 4:22am    
In which case use Directory.GetFiles - it has an overload that takes options which allow "All Directories".
You can then use FileInformation to identify the creation period and delete the "older" material. If necessary, you can then recursively traverse the folders deleting "empties".
NaVeN Kumar 25-Jul-14 4:34am    
Yes It worked when I used

Directory.GetFiles(directoryPath, "*", System.IO.SearchOption.AllDirectories);

Thank you so much... :)
OriginalGriff 25-Jul-14 4:40am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900