jammy-d0dger
asked on
Delete files from multiple subfolders in ASP.NET
Hi Experts,
Is there any way in ASP.NET, (vb please), that one can issue a command to delete a given filename from a given path but to also delete it from any subfolders that may exist? i.e. the file for deletion can exist in multiple folders and I want to delete any instance that may or may not occur in each subfolder?
Help appreciated as always,
Jay
Is there any way in ASP.NET, (vb please), that one can issue a command to delete a given filename from a given path but to also delete it from any subfolders that may exist? i.e. the file for deletion can exist in multiple folders and I want to delete any instance that may or may not occur in each subfolder?
Help appreciated as always,
Jay
ASKER
thanks for the reply but not quite what I'm looking for. I'm aware that I could write a bit of code to loop through 'known' subfolders and look for a file, but using this snippet, I would need to know all the names of the subfolders first. Ideally what I'd like to do is delete a certain file from 'any' subfolder that 'might' exist, i.e. like a wildcard, so that I don't need to know the subfolder list in advance, (or care for that matter!).
For instance, if I were in DOS, I would say
"del *.jpg /S"
and this would delete all jpg files from the current folder and all subfolders.
For instance, if I were in DOS, I would say
"del *.jpg /S"
and this would delete all jpg files from the current folder and all subfolders.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm probably being a bit paranoid but 'actually' dropping to DOS on a web app, feels a bit... uncontrolled. I know it's my own fault for mentioning it but I just thought it showed what I was trying to achieve, I wasn't expecting you to suggest I actually run it as a command. It's very interesting that it can be done, but I'd feel worried about this fire and forget approach for deleting files en-masse.
I think I have found the .NET function I need, DirectoryInfo.GetFileSyste mInfos Method (String)
http://msdn.microsoft.com/en-us/library/3xy7db0w.aspx
Using this I will be able to build a list of subfolders on the fly, then traverse them all and search for the filename string required and then issue the delete command. Doing it this way, I will feel more in control of what's going on, so to speak.
I think I have found the .NET function I need, DirectoryInfo.GetFileSyste
http://msdn.microsoft.com/en-us/library/3xy7db0w.aspx
Using this I will be able to build a list of subfolders on the fly, then traverse them all and search for the filename string required and then issue the delete command. Doing it this way, I will feel more in control of what's going on, so to speak.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that 'looks' like an excellent chunk of code there rdogmartin! I have to leave my desk for a bit right now but will try this approach later and report back. thanks for help so far guys.
ASKER
Thanks for your help on this question. The code snippet provided by rdogmartin worked like a charm, perfectly achieving what I'd set out to do. So I've awarded the lion's share to rdog but felt that I should give 50 points to om_prakash_p for the interesting link re: running DOS commands.
Thanks again experts.
Thanks again experts.
http://www.dreamincode.net/code/snippet1566.htm
this deletes all files from folder & sub folder but can be modified to search & delete specific file from all location.