MarkMarkMark Posted May 13, 2005 Share Posted May 13, 2005 Hi guys, Yeah its me again, I have some questions... Here is the case: I have a folder with 20 files in it, all named like this: aa1.*** (*** stands for something) al files have the extension .txt now i want autoit to grab the 1st file (not the autoitscript itself), rename it to "running.txt" ,wait 2 minutes , deletes the file, grab the next file and rename that to running.txt, wait 2 minuten, delete the file, grab the next file... and on an on and on until the folder is empty. I asked a couple of weeks a question bout something that looks like this and i've been playing with the code a bit but i cant figure it out: ; Shows the filenames of all files in the current directory $search = FileFindFirstFile("*.*") ; 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;done finding files MsgBox(4096, "File:", $file) ; Check if file opened for reading OK If $file = -1 Then ContinueLoop;couldn't open file; continue with next file ;throw away the first 10 lines For $i = 1 to 10 FileReadLine($file) Next While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop FileWriteLine($file & ".new.txt", $line) Wend WEnd ; Close the search handle FileClose($search) This code trows away the 1st 10 lines of each document. But now i want to mod this script to my needs but i cant get it working... any1 go some idea's? Thanks alot. -mark Link to comment Share on other sites More sharing options...
steveR Posted May 13, 2005 Share Posted May 13, 2005 untestedexpandcollapse popup; Shows the filenames of all files in the current directory $search = FileFindFirstFile("*.*") ; 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;done finding files MsgBox(4096, "File:", $file) ; Check if file opened for reading OK If $file = -1 Then ContinueLoop;couldn't open file; continue with next file ;throw away the first 10 lines ;~ For $i = 1 to 10 ;~ FileReadLine($file) ;~ Next ;~ ;~ While 1 ;~ $line = FileReadLine($file) ;~ If @error = -1 Then ExitLoop ;~ FileWriteLine($file & ".new.txt", $line) ;~ Wend If $file <> "Yourscript.au3" Then; skip your script FileMove($file, "running.txt", 1); rename as running.txt Sleep(2 * 60 * 1000); wait 2 min FileDelete("running.txt) EndIf WEnd ; Close the search handle FileClose($search) AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass. Link to comment Share on other sites More sharing options...
MarkMarkMark Posted May 13, 2005 Author Share Posted May 13, 2005 Mmm, you missed 1 " at the end of FileDelete("running.txt) but next to that, the script does this now: Give a msgbox with "." then delete all files, including the script... and leaves only the 1st file in the directory and renamed that to running.txt.. mmm this is not good Link to comment Share on other sites More sharing options...
MHz Posted May 13, 2005 Share Posted May 13, 2005 Mmm, you missed 1 " at the end of FileDelete("running.txt)but next to that,the script does this now:Give a msgbox with "."then delete all files, including the script... and leaves only the 1st file in the directory and renamed that to running.txt..mmm this is not good <{POST_SNAPBACK}>True, some mistakes, but untested. Have a look in the Helpfile for FileFindFirstFile.Then you can correct it yourself. Correcting someone's code is a good way to learn also.I would assume this is missing from the loop ?If '.' Then ContinueLoop If '..' Then ContinueLoop If @ScriptName Then ContinueLoop Link to comment Share on other sites More sharing options...
MarkMarkMark Posted May 13, 2005 Author Share Posted May 13, 2005 Ok, Im a bit on the way i think (...) $search = FileFindFirstFile("*.*") 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 If $file = -1 Then ContinueLoop If '.' Then ContinueLoop If '..' Then ContinueLoop If @ScriptName Then ContinueLoop If '*.txt' Then go() MsgBox(4096, "File:", $file) WEnd FileClose($search) func go() FileMove($file, "running.txt", 1) Sleep(2 * 60 * 1000); wait 2 min FileDelete("running.txt") endfunc Am i doing this right? tnx in advanced... -Mark Link to comment Share on other sites More sharing options...
steveR Posted May 13, 2005 Share Posted May 13, 2005 (edited) Oops sorry, I intentionany left skipping . and .. out because I thought since it wasn't included already thatIf $file = -1 Then ContinueLoop;couldn't open file; continue with next file was skipping past them. As for the missing ", yes my fault. Yes looks ok now Edit: Darn sticky keys was off Edited May 13, 2005 by steveR AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass. Link to comment Share on other sites More sharing options...
MHz Posted May 13, 2005 Share Posted May 13, 2005 Try this instead: $search = FileFindFirstFile("*.*") 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 If $file = '.' Then ContinueLoop If $file = '..' Then ContinueLoop If $file = @ScriptName Then ContinueLoop go() WEnd ; Close the search handle FileClose($search) Func go() FileMove($file, "running.txt", 1) Sleep(2 * 60 * 1000); wait 2 min FileDelete("running.txt") EndFunc Link to comment Share on other sites More sharing options...
MarkMarkMark Posted May 13, 2005 Author Share Posted May 13, 2005 tnx guys, that worked great 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