Garrett19212 Posted July 11, 2005 Share Posted July 11, 2005 How can I make it so it searches the whole computer for a file? And if it finds it, it deletes it? I tried FileFindFirstFile but I can't get it to work right. Link to comment Share on other sites More sharing options...
GaryFrost Posted July 11, 2005 Share Posted July 11, 2005 Search in Scripts and Scraps, there's a few FileSearch UDF's there that should do the job. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Garrett19212 Posted July 11, 2005 Author Share Posted July 11, 2005 I couldn't find anything that looks like that I need, or atleast it doesn't look what I need. Im new to AU3 so still learning what everything does. I have a txt file, with a filename on each line. And I have a loop which sets the next line to a variable, which the FileFindFirstFile set to search for the variable. But its not working, i made a file with the exact name of what I want it so look for, but it doesn't find it. How can I make it search the whole C: drive, for the file? Link to comment Share on other sites More sharing options...
therks Posted July 11, 2005 Share Posted July 11, 2005 You could do something like this (I'm not at home and cannot test this, so bear in mind I may have written a function name wrong or something): $resultFile = 'c:\SearchResults.txt' $file = 'stupidfile.exe' RunWait(@ComSpec & ' /c dir "' & $file & '" /b/s > "' & $resultFile & '"', 'C:\', @SW_HIDE) If FileSize($resultFile) = 0 Then MsgBox(0, 'File Not Found', 'File Not Found') Else $searchResults = FileRead($resultFile, FileSize($resultFile)) EndIf Give it a try. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Garrett19212 Posted July 11, 2005 Author Share Posted July 11, 2005 Seems to work, changed filesize to filegetsize and im not getting any errors so. How would I make it so that if it finds something it deletes it? Link to comment Share on other sites More sharing options...
Garrett19212 Posted July 11, 2005 Author Share Posted July 11, 2005 bump^ Link to comment Share on other sites More sharing options...
blindwig Posted July 11, 2005 Share Posted July 11, 2005 Seems to work, changed filesize to filegetsize and im not getting any errors so.How would I make it so that if it finds something it deletes it?<{POST_SNAPBACK}>Have you tried FileDelete()? My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Garrett19212 Posted July 11, 2005 Author Share Posted July 11, 2005 what would i put for it though, since the file isnt in the folder where the script? Ill try FileDelete($file) and see what happens. Link to comment Share on other sites More sharing options...
Garrett19212 Posted July 11, 2005 Author Share Posted July 11, 2005 Nope, i made it search for a file called 4096, and i made a file called 4096 and put it on my desktop and it didn't delete it. Link to comment Share on other sites More sharing options...
Brona Posted July 11, 2005 Share Posted July 11, 2005 I added the following to the script and it appears to work: $file = FileOpen($resultFile, 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop FileDelete($line) Wend FileClose($file) ;FileDelete($resultFile) Not All Who Wander Are Lost Link to comment Share on other sites More sharing options...
Garrett19212 Posted July 11, 2005 Author Share Posted July 11, 2005 $resultFile = 'c:\SearchResults.txt' $file = 'stupidfile.exe' RunWait(@ComSpec & ' /c dir "' & $file & '" /b/s > "' & $resultFile & '"', 'C:\', @SW_HIDE) If FileSize($resultFile) = 0 Then MsgBox(0, 'File Not Found', 'File Not Found') Else $searchResults = FileRead($resultFile, FileSize($resultFile)) EndIf $file = FileOpen($resultFile, 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop FileDelete($line) Wend FileClose($file) ;FileDelete($resultFile) Like that? Is the ; suppose to be by the filedelete Link to comment Share on other sites More sharing options...
blindwig Posted July 11, 2005 Share Posted July 11, 2005 You could do something like this (I'm not at home and cannot test this, so bear in mind I may have written a function name wrong or something):$resultFile = 'c:\SearchResults.txt' $file = 'stupidfile.exe' RunWait(@ComSpec & ' /c dir "' & $file & '" /b/s > "' & $resultFile & '"', 'C:\', @SW_HIDE) If FileSize($resultFile) = 0 Then MsgBox(0, 'File Not Found', 'File Not Found') Else $searchResults = FileRead($resultFile, FileSize($resultFile)) EndIfGive it a try.<{POST_SNAPBACK}>You probably want to start the search at the root of the drive:RunWait(@ComSpec & ' /c dir "' & $file & '" /b/s > "' & $resultFile & '"', 'C:\', @SW_HIDE) My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
blindwig Posted July 11, 2005 Share Posted July 11, 2005 (edited) Since you're just shelling out to run the DIR command, why even bother with autoit? Why not just write a batch file?RecursiveDelete.Bat:FOR /F "tokens=*" %%A in ('DIR "\%~1" /s/b') do DEL %%AThen call it like this:RecursiveDelete FileName.Extit will also work for wildcards.EDIT: Oh, I forgot to mention - this method won't work on Windows 9x or WindowsNT 4 or earlier. I don't know about ME. Edited July 11, 2005 by blindwig My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Garrett19212 Posted July 11, 2005 Author Share Posted July 11, 2005 I would like to do it in Autoit. $resultFile = 'c:\SearchResults.txt' $file = 'stupidfile.exe' RunWait(@ComSpec & ' /c dir "' & $file & '" /b/s > "' & $resultFile & '"', 'C:\', @SW_HIDE) If GetFileSize($resultFile) = 0 Then MsgBox(0, 'File Not Found', 'File Not Found') Else $searchResults = FileRead($resultFile, GetFileSize($resultFile)) EndIf How would I make that, delete the files it finds? Link to comment Share on other sites More sharing options...
Brona Posted July 11, 2005 Share Posted July 11, 2005 (edited) Like that?Is the ; suppose to be by the filedelete<{POST_SNAPBACK}>That last ; I put in just in case you did not want to delete the 'SearchResults.txt' file when you are done ... I did on mine as not to leave any files behind when done running the script. Edited July 11, 2005 by Brona Not All Who Wander Are Lost Link to comment Share on other sites More sharing options...
blindwig Posted July 11, 2005 Share Posted July 11, 2005 I would like to do it in Autoit.Then take out the RunWait line and use FileFindFirstFile. Look at the example in the help file, it shows you exactly how to loop through the files, matched by a mask.$resultFile = 'c:\SearchResults.txt'$file = 'stupidfile.exe'RunWait(@ComSpec & ' /c dir "' & $file & '" /b/s > "' & $resultFile & '"', 'C:\', @SW_HIDE)If GetFileSize($resultFile) = 0 Then MsgBox(0, 'File Not Found', 'File Not Found')Else $searchResults = FileRead($resultFile, GetFileSize($resultFile))EndIfHow would I make that, delete the files it finds?The files that it finds will be listed in the $resultFile, so go through that file and delete each file entry. Use FileOpen, FileReadLine, and FileClose, to use the file. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now