LagunaScripter Posted November 13, 2009 Share Posted November 13, 2009 (edited) Hi everyone, I found a sample script on this forum that I shamelessly tried to model something after, but I just can't seem to figure out why things aren't working. Here is what I am trying to do: I want to be able to invoke the script from a command line in the syle of: "Filemanipulator.exe (path) (extension)". I want to script to recursively scan the folder specified in (path) and perform an action on all files with the specified extension. The problem is that the script doesn't end, it somehow gets lost in the loops and paths and extensions. The adapted script follows, I'd greatly appreciate any help anyone can lend. expandcollapse popup;Recursive File manipulator Dim $FolderName = $Cmdline[1] Dim $FileCount = 0 Dim $Extension = $Cmdline[2] MsgBox(0,"Debug","$Foldername is "&$Foldername) ScanFolder($FolderName) MsgBox(0,"Done","Folder Scan Complete. Scanned " & $FileCount & " Files") Func ScanFolder($SourceFolder) MsgBox(0,"Debug","Entered Scanfolder function") Local $Search Local $File Local $FileAttributes Local $FullFilePath MsgBox(0,"Debug","Search receives " & $SourceFolder & "\*.*") $Search = FileFindFirstFile($SourceFolder & "\*.*") MsgBox(0,"Debug","$Search is= "&$Search) While 1 If $Search = -1 Then ExitLoop EndIf $File = FileFindNextFile($Search) MsgBox(0,"Debug","$File receives "& FileFindNextFile($Search)) MsgBox(0,"Debug", "$File is "& $File) If @error Then ExitLoop MsgBox(0,"Debug", "Fullfilepath receives " & $Sourcefolder & "\" & $File) $FullFilePath = $SourceFolder & "\" & $File MsgBox(0,"Debug","$FullFilePath is " & $FullFilePath) MsgBox(0,"Debug","$FileAttributes receive " & FileGetAttrib($FullFilePath)) $FileAttributes = FileGetAttrib($FullFilePath) If StringInStr($FileAttributes,"D") Then ScanFolder($FullFilePath) Else MsgBox(0,"Debug", "About to test extension. $FullFilePath is " & $FullFilePath & " $Extension is " & $Extension) If StringInStr($FullFilePath, $Extension) Then MsgBox(0,"Debug", "Extension matched, manipulating file. $FullFilePath= " & $FullFilePath & " $Extenion=" & $Extension) LogFile($FullFilePath) EndIf EndIf FileClose($Search) WEnd FileClose($Search) EndFunc Func LogFile($FileName) ;This is where I "do something" to the file FileWriteLine(@ScriptDir & "\FileList.txt",$FileName) $FileCount += 1 ToolTip($FileName,0,0) EndFunc Edited November 13, 2009 by LagunaScripter Link to comment Share on other sites More sharing options...
omikron48 Posted November 13, 2009 Share Posted November 13, 2009 (edited) expandcollapse popup;Recursive File manipulator Dim $FolderName = $Cmdline[1] Dim $FileCount = 0 Dim $Extension = $Cmdline[2] MsgBox(0,"Debug","$Foldername is "&$Foldername) ScanFolder($FolderName) MsgBox(0,"Done","Folder Scan Complete. Scanned " & $FileCount & " Files") Func ScanFolder($SourceFolder) MsgBox(0,"Debug","Entered Scanfolder function") Local $Search Local $File Local $FileAttributes Local $FullFilePath MsgBox(0,"Debug","Search receives " & $SourceFolder & "\*.*") $Search = FileFindFirstFile($SourceFolder & "\*.*") MsgBox(0,"Debug","$Search is= "&$Search) While 1 If $Search = -1 Then ExitLoop EndIf $File = FileFindNextFile($Search) If @error Then ExitLoop ;#EDIT# ;MsgBox(0,"Debug","$File receives "& FileFindNextFile($Search)) #EDIT# MsgBox(0,"Debug", "$File is "& $File) MsgBox(0,"Debug", "Fullfilepath receives " & $Sourcefolder & "\" & $File) $FullFilePath = $SourceFolder & "\" & $File $FileAttributes = FileGetAttrib($FullFilePath) MsgBox(0,"Debug","$FullFilePath is " & $FullFilePath) MsgBox(0,"Debug","$FileAttributes receive " & FileGetAttrib($FullFilePath)) If StringInStr($FileAttributes,"D") Then ScanFolder($FullFilePath) Else MsgBox(0,"Debug", "About to test extension. $FullFilePath is " & $FullFilePath & " $Extension is " & $Extension) If StringInStr($FullFilePath, $Extension) Then MsgBox(0,"Debug", "Extension matched, manipulating file. $FullFilePath= " & $FullFilePath & " $Extenion=" & $Extension) LogFile($FullFilePath) EndIf EndIf FileClose($Search) WEnd FileClose($Search) EndFunc Func LogFile($FileName) ;This is where I "do something" to the file FileWriteLine(@ScriptDir & "\FileList.txt",$FileName) $FileCount += 1 ToolTip($FileName,0,0) EndFunc Edited November 13, 2009 by omikron48 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