leveex Posted December 12, 2006 Share Posted December 12, 2006 Need help with creating script that will look for a files from external file list and delete all files from list if they exsist on my local drive E:\ F:\ Link to comment Share on other sites More sharing options...
xcal Posted December 12, 2006 Share Posted December 12, 2006 What part are you stuck on? How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
leveex Posted December 12, 2006 Author Share Posted December 12, 2006 On the beginning... Can't find commands for find files... So if you can give me some hint where I can find useful command list or something similar I'll be grateful. Al what have I found is tutorial to create hello world Link to comment Share on other sites More sharing options...
boltc Posted December 12, 2006 Share Posted December 12, 2006 i found this: expandcollapse popup; AutoIt Version: 3.0 ; Language: English ; Platform: Win9x/NT/XP ; Author: jos van der Zande ; ; Find files in directory and subdirectories and return it in an Array, all coded in Autoit3 ; Dim $FILES Dim $DIR="c:\" ; specify the directory to search Dim $FILEMASK="*.txt" ; specify the filemask $FILES = _GetFileList($DIR, $FILEMASK) For $X = 0 To UBound($FILES)-1 MsgBox(0,'test:' & $X,$FILES[$X]) Next Exit ;******************************************************************************** ;Recursive search for filemask ;******************************************************************************** Func _GetFileList($T_DIR,$T_MASK) Dim $N_DIRNAMES[200000]; max number of directories that can be scanned Local $N_DIRCOUNT = 0 Local $N_FILE Local $N_SEARCH Local $N_TFILE Local $N_OFILE Local $T_FILENAMES Local $T_FILECOUNT Local $T_DIRCOUNT = 1 ; remove the end \ If specified If StringRight($T_DIR,1) = "\" Then $T_DIR = StringTrimRight($T_DIR,1) $N_DIRNAMES[$T_DIRCOUNT] = $T_DIR ; Exit if base dir doesn't exists If Not FileExists($T_DIR) Then Return 0 ; keep on looping until all directories are scanned While $T_DIRCOUNT > $N_DIRCOUNT $N_DIRCOUNT = $N_DIRCOUNT + 1 ; find all subdirs in this directory and save them in a array $N_SEARCH = FileFindFirstFile($N_DIRNAMES[$N_DIRCOUNT] & "\*.*") While 1 $N_FILE = FileFindNextFile($N_SEARCH) If @error Then ExitLoop ; skip these references If $N_FILE = "." Or $N_FILE = ".." Then ContinueLoop $N_TFILE = $N_DIRNAMES[$N_DIRCOUNT] & "\" & $N_FILE ; if Directory than add to the list of directories to be processed If StringInStr(FileGetAttrib( $N_TFILE ),"D") > 0 Then $T_DIRCOUNT = $T_DIRCOUNT + 1 $N_DIRNAMES[$T_DIRCOUNT] = $N_TFILE EndIf Wend FileClose($N_SEARCH) ; find all Files that mtach the MASK $N_SEARCH = FileFindFirstFile($N_DIRNAMES[$N_DIRCOUNT] & "\" & $T_MASK ) If $N_SEARCH = -1 Then ContinueLoop While 1 $N_FILE = FileFindNextFile($N_SEARCH) If @error Then ExitLoop ; skip these references If $N_FILE = "." Or $N_FILE = ".." Then ContinueLoop $N_TFILE = $N_DIRNAMES[$N_DIRCOUNT] & "\" & $N_FILE ; if Directory than add to the list of directories to be processed If StringInStr(FileGetAttrib( $N_TFILE ),"D") = 0 Then $T_FILENAMES = $T_FILENAMES & $N_TFILE & @CR $T_FILECOUNT = $T_FILECOUNT + 1 ;MsgBox(0,'filecount ' & $T_FILECOUNT ,$N_TFILE) EndIf Wend FileClose($N_SEARCH) Wend $T_FILENAMES = StringTrimRight($T_FILENAMES,1) $N_OFILE = StringSplit($T_FILENAMES,@CR) Return( $N_OFILE ) EndFunc ;==>_GetFileList Link to comment Share on other sites More sharing options...
boltc Posted December 12, 2006 Share Posted December 12, 2006 i have tested the script.. it works nice, but also it also search in de supdirectories Link to comment Share on other sites More sharing options...
leveex Posted December 12, 2006 Author Share Posted December 12, 2006 Yes this is helpful, but this only search for for files that are in file mask. Or? I have playing a little bit and found some thing like this: $file = FileOpen("D:\example.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $amount = 0 ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $len = StringLen($line) While 1 $result1= StringTrimLeft($line, $amount) $result2= StringTrimRight($result1, $len-12-$amount) FileChangeDir("C:\") If FileExists($result2) Then Else MsgBox(4096,"DOES NOT EXISTS!!!", $result2) EndIf $amount = $amount + 13 If $amount>= $len Then ExitLoop WEnd Wend FileClose($file) MsgBox(4096,"COMPLETE", "STATUS OK") But problem is because this don't look in subfolders (that isn't so big problem) Problem that badgering me is how to tell script that it needs to delete those files? Link to comment Share on other sites More sharing options...
Valuater Posted December 12, 2006 Share Posted December 12, 2006 without going through the entire structure maybe... If FileExists($result2) Then ;FileDelete($result2) Else MsgBox(4096,"DOES NOT EXISTS!!!", $result2) EndIf remove the ";" to use that line 8) Link to comment Share on other sites More sharing options...
leveex Posted December 13, 2006 Author Share Posted December 13, 2006 I thought that it' will be easier, but can't get it to search in subfolders. I try it to combine both script into one but it wasnt successful. Don't understand which command exactly is from first script to look in subfolders? Link to comment Share on other sites More sharing options...
MHz Posted December 13, 2006 Share Posted December 13, 2006 Don't understand which command exactly is from first script to look in subfolders?Perhaps this is easier to use. $file = 'test.txt' RunWait(@ComSpec & ' /c del /s/q "' & $file & '"', 'e:\', @SW_HIDE) Link to comment Share on other sites More sharing options...
leveex Posted December 13, 2006 Author Share Posted December 13, 2006 won't work, even won't close window maybe I am done something wrong. Here is what have I done. expandcollapse popup;Find text script; $file = 'test.txt' RunWait(@ComSpec & ' /c del /s/q "' & $file & '"', 'C:\', @SW_HIDE) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $amount = 0 ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $len = StringLen($line) While 1 $result1= StringTrimLeft($line, $amount) $result2= StringTrimRight($result1, $len-13-$amount) FileChangeDir("C:\Input") If FileExists($result2) Then FileDelete($result2) Else MsgBox(4096,"DOES NOT EXISTS!!!", $result2) EndIf $amount = $amount + 13 If $amount>= $len Then ExitLoop WEnd Wend FileClose($file) MsgBox(4096,"COMPLETE", "STATUS OK") Link to comment Share on other sites More sharing options...
leveex Posted December 15, 2006 Author Share Posted December 15, 2006 c'mon please help me... I'm so close to the end.... Link to comment Share on other sites More sharing options...
leveex Posted December 15, 2006 Author Share Posted December 15, 2006 expandcollapse popup;Find text script; $file = 'test.txt' RunWait(@ComSpec & ' /c del /s/q "' & $file & '"', 'C:\', @SW_HIDE) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $amount = 0 ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $len = StringLen($line) While 1 $result1= StringTrimLeft($line, $amount) $result2= StringTrimRight($result1, $len-13-$amount) FileChangeDir("C:\Input") If FileExists($result2) Then FileDelete($result2) Else MsgBox(4096,"DOES NOT EXISTS!!!", $result2) EndIf $amount = $amount + 13 If $amount>= $len Then ExitLoop WEnd Wend FileClose($file) MsgBox(4096,"COMPLETE", "STATUS OK") where is the problem.... 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