kkman360 Posted April 10, 2006 Posted April 10, 2006 (edited) code: $search = FileFindFirstFile("c:\temp") 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 FileChangeDir ( "C:\TEMP\"& $file ) RunWait(@COMSPEC & " /c SNACFG #com.cfg /PRINT >COM.TXT") WEnd FileClose($search) it can'nt work ,how should i do ? thanks! Edited April 10, 2006 by kkman360
jpm Posted April 10, 2006 Posted April 10, 2006 code:$search = FileFindFirstFile("c:\temp") If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") ExitEndIfWhile 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileChangeDir ( "C:\TEMP\"& $file ) RunWait(@ComSpec & " /c " & SNACFG #com.cfg /PRINT >COM.TXT, "", @SW_HIDE)WEndFileClose($search)it can'nt work 1how should i do ?thanks!your findfirstfile just search for the file or directory temp.So it is normal that the FileFindnextFile will not find anything else.
kkman360 Posted April 10, 2006 Author Posted April 10, 2006 your findfirstfile just search for the file or directory temp.So it is normal that the FileFindnextFile will not find anything else. i have 1200 folders in temp i want go to each folder and do snacfg /print >com.txthow should i do ?i use RunWait(@COMSPEC & " /c SNACFG #com.cfg /PRINT >COM.TXT")and it can work.but don't chang the path .thank for your reply so fast !
MHz Posted April 10, 2006 Posted April 10, 2006 Here is a variation to your script. If FileChangeDir("c:\temp") Then $search = FileFindFirstFile("*") If $search <> -1 Then While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file = '.' Or $file = '..' Then ContinueLoop If FileChangeDir($file) Then RunWait(@ComSpec & " /c SNACFG #com.cfg /PRINT >COM.TXT", @WorkingDir, @SW_HIDE) FileChangeDir('..') EndIf WEnd FileClose($search) Else MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf EndIf The working directory is the temp directory and each file/folder found will be tested with FileChangeDir. Success will execute you Run() function and change directory up a level again. And will just keep looping until the end.
kkman360 Posted April 10, 2006 Author Posted April 10, 2006 Here is a variation to your script. If FileChangeDir("c:\temp") Then $search = FileFindFirstFile("*") If $search <> -1 Then While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file = '.' Or $file = '..' Then ContinueLoop If FileChangeDir($file) Then RunWait(@ComSpec & " /c SNACFG #com.cfg /PRINT >COM.TXT", @WorkingDir, @SW_HIDE) FileChangeDir('..') EndIf WEnd FileClose($search) Else MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf EndIf The working directory is the temp directory and each file/folder found will be tested with FileChangeDir. Success will execute you Run() function and change directory up a level again. And will just keep looping until the end.thank you very much !it work fine.
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