Click here to Skip to main content
15,944,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a folder with in that folder i have some subfolder's, each subfolder contains some files, so first i need to take first subfolder and get the files from directory and send to my application after iterating all the files need to be deleted as well as the subfolder also need to be delete, next move to second subfolder and do the same procedure until the Main/root folder is empty.
Posted
Comments
Suvendu Shekhar Giri 24-Jun-15 0:47am    
So, what is the problem implementing your logic?
Why not copying all the files at once and then delete the complete structure ?
Is there any specific reason for doing that?
Vijay533 24-Jun-15 4:50am    
Hi shekhar giri, the problem has solved, but i have a question, i need to send multiple files to my exe for indexing/stores the documents how to do that thing.

1 solution

There are loads of ways you could do this, but the easiest is just to get all the files:
C#
string[] files = Directory.GetFiles(pathToFolder, "*.*", SearchOption.AllDirectories);
This returns an array of strings which contain the full path to each file in the specified folder, or any subfolder.
You can then process the files sequentially via a simple loop, and use File.Delete to remove each of them when finished.
When complete, you can use Directory.GetDirectories to list each of the folders in the main path, and delete them with:
Directory.Delete(path, true);
Alternatively, delete the base folder, and recreate it.
 
Share this answer
 
Comments
Vijay533 24-Jun-15 2:53am    
Thanks OriginalGriff
Vijay533 24-Jun-15 2:54am    
I have a question Griff, i have files in folder i need to send all the files at a time to my application what i need to do for that?
OriginalGriff 24-Jun-15 3:14am    
You're going to have to be rather more specific than that! :laugh:

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