Jump to content

Find and exterminate


duhu
 Share

Recommended Posts

I am disperate ! I want to make a script that finds and deletes all the files/folders that contains a specified keyword(the keyword I want)

Exemple:

I want the script to do this:

-Searches my computer for the files that contain (lets say. 123 ) in their name and then deletes them.

Help plss.

srry for my eng

Doohoodogg

Link to comment
Share on other sites

I want the script to do this:

-Searches my computer for the files that contain (lets say. 123 ) in their name and then deletes them.

<{POST_SNAPBACK}>

I sent this an hour or so ago, but it never arrived. So here it is again.

The following will locate all files on c-drive with "123" anywhere in the filename and write the path and filename to a text file. Just write a loop to read each line of the file and delete the file it identifies. Note that the DIR command will also find files with the same characters even if there are spaces between each character. For example, "C:\abc\my_1 2 3.txt".

SplashTextOn('Locating files', 'Locating all files with "123" in their names' &@lf& 'Please wait for command window to close...')
RunWait(@comspec & ' /c dir "c:\*123*.*" /b/oN/s > "c:\all-123.txt"')
splashoff()
MsgBox(4096, 'x', 'The names of the files are in c:\all-123.txt')

Your English sounds good to me.

Phillip

Link to comment
Share on other sites

...Just write a loop to read each line of the file and delete the file it identifies...

<{POST_SNAPBACK}>

Or skip all that work and use the "Del" command instead of "Dir".

Sounds pretty dangerous to me.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

U mean like this

RunWait(@comspec & ' /c dir "c:\*blablabla*.*" /b/oN/s > "c:\I found this files.txt"')

That didnt work

<{POST_SNAPBACK}>

I copied your code and it worked for me. Of course I had to create some files with "blablabla" in their names.

The syntax for the DEL command is different than the DIR command. At a command prompt, type HELP DIR and HELP DEL to examine them.

Here's the script for the DEL command. Please review the syntax before using it, and be very careful with the wild cards. The good thing about the DIR command is it makes a list of files you can review before deleting anything.

RunWait(@comspec & ' /c del "c:\*blablabla*.*" /q/s > "c:\I deleted these files.txt"')

Phillip

Link to comment
Share on other sites

...Just write a loop to read each line of the file and delete the file it identifies.

<{POST_SNAPBACK}>

This was the "work" that I was suggesting be skipped by using the DEL command instead of AutoIt functions.

...The good thing about the DIR command is it makes a list of files you can review before deleting anything.

<{POST_SNAPBACK}>

I would still use the DIR to gen a list that could be reviewed and then have the script call DEL for the actual deletion followed by another DIR just to verify the results.

Also, I think that *123*.* can be changed to *123* with the same results - could be wrong.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

This was the "work" that I was suggesting be skipped by using the DEL command instead of AutoIt functions.

I would still use the DIR to gen a list that could be reviewed and then have the script call DEL for the actual deletion followed by another DIR just to verify the results.

<{POST_SNAPBACK}>

@herewasplato,

Are you saying you would use the Windows DEL command instead of the AutoIt FileDelete function? It seems to me that if I am going to review a text file of the files matching the wild card search, I would remove from the text file any files I do not want deleted, and in an AutoIt loop I would use the file FileDelete function to delete individual files. Am I missing something?

Phillip

Link to comment
Share on other sites

@herewasplato,

Are you saying you would use the Windows DEL command instead of the AutoIt FileDelete function?  It seems to me that if I am going to review a text file of the files matching the wild card search, I would remove from the text file any files I do not want deleted, and in an AutoIt loop I would use the file FileDelete function to delete individual files.  Am I missing something?

<{POST_SNAPBACK}>

Yes, that is what I'm saying,

"...use the Windows DEL command instead of the AutoIt FileDelete function":

AutoIt - DIR to text file

AutoIt - text file to notepad

Human - review text

Human - rename or move files to keep

AutoIt - DEL to delete the remaining files...

Rename or move the files to be kept while the script is paused during the review process or they will just show up the next time and the next time and the next time.... I had thought of using the AutoIt FileDelete function in exactly the way you mentioned, but then I thought better of it. If the process of tracking down and deleting these files was needed so often that it was to be scripted, then repeatedly removing those files to be kept from the text file would be a pain. It would be better to rename or move them.

I saw the first post and opt'd not to reply to it right away. I wanted to see what others would post. Had I replied first, I probably would have suggested not using an AutoIt script - I would have suggested a single line BAT file... if you were really sure that you wanted all such files gone! (I still think that this is a bad idea for the entire drive.)

Since we have now gone down the road that includes:

search/review results/edit results/delete remaining

...might I suggest another non-scripted route?

Human - open the OS native file search window

Human - type in criteria (like 123)

Human - press search

Human - move/rename files to keep

Human - delete the rest (you had better be sure)

It is a few more steps for the human, but the OS native file search window gives (or can give) so much info about the files in question that I think that it is worth the steps.

sorry for the long post just way too many thoughts for such a simple topic

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Yes, that is what I'm saying,

"...use the Windows DEL command instead of the AutoIt FileDelete function":

AutoIt - DIR to text file

AutoIt - text file to notepad

Human - review text

Human - rename or move files to keep

AutoIt - DEL to delete the remaining files...

<{POST_SNAPBACK}>

Okay, if you can rename or move all of the files that must be kept, a wild card delete via the DEL command is cool.

Food for thought! For the condition you describe, the script could maintain a list of files that are not to be deleted, and auto remove them from the list produced by DIR before deleting the remaining files using FileDelete. That way, no files would have to be removed or renamed.

Phillip

Link to comment
Share on other sites

Can someone post the an example of script that read the " found this files.txt"

that is created with dir and delete the files that are listed in the "found this files.txt" because i'm a little confuse!

Thx

Doohoodogg

Anyway, thx all f helping a n00b like me.

Link to comment
Share on other sites

...Food for thought!...

<{POST_SNAPBACK}>

good thought - go for it :-)

...i'm a little confuse!

<{POST_SNAPBACK}>

Sorry, I probably should have stayed out of this thread and it would not have been so confusing :-(

phillip123adams is giving you excellent scripting advise... you two work out the details of your request.

later....

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Can someone post the an example of script that read the " found this files.txt"

that is created with dir and delete the files that are listed in the "found this files.txt" because i'm a little confuse!

<{POST_SNAPBACK}>

You will need the following AutoIt3 functions and macro to develop a script that can read the data file and delete the files it lists. Look them up in the AutoIt3 help file which has very good examples for them (FileReadLine shows how to read each line of the text file). Give it a try, and if you get stuck, post your code and I, or someone, will help.

FileOpen

While

FileReadLine

If

@error

ExitLoop

FileDelete

Wend

FileClose

You may also want to redo the MsgBox so it displays the YES and NO buttons and knows which button gets clicked. That way the script will wait for you to tell it what to do after it lists the files. For example:

$sReply = MsgBox(4100, "Files to be deleted", "The names of the files are in c:\I found these files.txt." &@lf&@lf& "Review it and remove any files that should not be deleted." &@lf& "Save the file and click this 'YES' button to delete the remaining names, or click 'NO' to abort.")

And you could have the script open the text file in NotePad, just before the MsgBox, so you can remove the names of files you do not want deleted. Since the filename contains spaces, it must have its own set of quotation marks. For example:

Run('notepad "c:\I found these files.txt"')

Are you using the SciTe for AutoIt editor? If not, I highly recommend it. It's free and can be download from http://www.autoitscript.com/autoit3/scite/downloads.php.

Phillip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...