NEOhidra Posted October 27, 2010 Posted October 27, 2010 Hi i am completly new to scripting and that is why i am asking here. I would like to ask if AutoIt can search a predefined directory fo two versions of one file and delete the older one (compare by name or file version/date of creation it does not matter). An example may be a better idea, something like Search C:\installer\ for installer_0.2.*.exe If C:\installer\ contains installer_0.2.4.exe and installer_0.2.5.exe then delete installer_0.2.4.exe Could you please help me? Or at least point me where/what should i read in order to make such script?
somdcomputerguy Posted October 27, 2010 Posted October 27, 2010 Welcome to the AutoIt forum. Some, or all, of these functions (found in the Help file), may be useful for this project.FileDeleteFileFindFirstFileFileFindNextFileFileGetSizeFileGetTimeFileGetVersion - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
NEOhidra Posted October 27, 2010 Author Posted October 27, 2010 I will try to do it as simple as possible (not that i understand something). Now i have this: If FileExists("C:\installer\installer_0.2.*.exe") Then ; Shows the filenames of all files in the current directory. $search = FileFindFirstFile("C:\installer\installer_0.2.*.exe") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileDelete("C:\installer\installer_0.2.*.exe") WEnd EndIf ; Close the search handle FileClose($search) FileDelete("C:\installer\installer_0.2.*.exe") deletes both files but whith what i should replace it in order to make AutoIt to delete the first file found?
NEOhidra Posted October 27, 2010 Author Posted October 27, 2010 If FileExists("C:\installer\installer_0.2.*.exe") Then ; Shows the filenames of all files in the current directory. $search = FileFindFirstFile("C:\installer\installer_0.2.*.exe") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileDelete("C:\installer\installer_0.2.*.exe") Then ExitLoop WEnd EndIf ; Close the search handle FileClose($search) And again both files are deleted. This is the output of SciTE: C:\ai\tes.au3 (15) : ==> Illegal text at the end of statement (one statement per line).: FileDelete("C:\MxDownload\miranda-im-v0.9.*-unicode.exe") Then ExitLoop FileDelete("C:\MxDownload\miranda-im-v0.9.*-unicode.exe") ^ ERROR
Oneqa Posted October 27, 2010 Posted October 27, 2010 (edited) Sry about the post before. Was phoning my gf while replying your email Here you go: expandcollapse popup$fPath = "C:\installer" $wildcard = "installer_0.2.*.exe" ;dont leave blank, will delete all file if do so $Fullfilename = SearchOneFile($fPath, $wildcard) If $Fullfilename <> "*" Then FileDelete($Fullfilename) Else MsgBox(0, "Error", "No files/directories matched the search pattern") EndIf Func SearchOneFile($path, $wCard = "*.*") Local $fullpath Local $search Local $file, $fAttrib $search = FileFindFirstFile($path & "\" & $wCard) While 1 If $search = -1 Or @error Then Return "*" EndIf $file = FileFindNextFile($search) If @error Then Return "*" EndIf $fullpath = $path & "\" & $file $fAttrib = FileGetAttrib($fullpath) If StringInStr($fAttrib, "D") = 0 Then ;is a file Return $fullpath Else $fullpath = SearchOneFile($fullpath, $wCard) If $fullpath <> "*" Then ExitLoop EndIf WEnd Return $fullpath EndFunc as a plus this will do recursive search within all subdirectory Edited October 27, 2010 by Oneqa
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