Trying To Remove All But Certain Directories

Recommended Posts

matthewst 0

matthewst 0

I need to delete a few hundred folders and files in a certain directory. The problem is I also need to keep a few of them. I have been trying to use DirRemove but I'm not sure how to make it remove all but the ones I need to keep.

Simply put:

I will run the script

it will go the defined directory

it will delete all files and folders except the ones i told it to leave alone earlier in the script

any advice would be greatly appreciated

Share this post

Link to post

Share on other sites

SmOke_N 203

SmOke_N 203

I need to delete a few hundred folders and files in a certain directory. The problem is I also need to keep a few of them. I have been trying to use DirRemove but I'm not sure how to make it remove all but the ones I need to keep.

Simply put:

I will run the script

it will go the defined directory

it will delete all files and folders except the ones i told it to leave alone earlier in the script

any advice would be greatly appreciated

I would imagine that you have to use the Beta FileFindFirstFile/NextFile and check those against what you've stored as do not delete. And delete the others if they don't match.

I guess you could also do a search in each director for specific files, and do a FileMove to a Temp Directory, and then just delete the Directory, then FileMove again (This might be quicker).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post

Link to post

Share on other sites

seandisanti 3

seandisanti 3

I would imagine that you have to use the Beta FileFindFirstFile/NextFile and check those against what you've stored as do not delete. And delete the others if they don't match.

I guess you could also do a search in each director for specific files, and do a FileMove to a Temp Directory, and then just delete the Directory, then FileMove again (This might be quicker).

i want to say that at the end of last summer, someone wanted to do the same thing for some school computers, where each user was allowed a "keep me" folder to be ignored and everything else was wiped out. i'll look it up and see if i can't find the code they used....

Share this post

Link to post

Share on other sites

matthewst 0

matthewst 0

i want to say that at the end of last summer, someone wanted to do the same thing for some school computers, where each user was allowed a "keep me" folder to be ignored and everything else was wiped out. i'll look it up and see if i can't find the code they used....