ChrisL Posted August 1, 2005 Share Posted August 1, 2005 (edited) Help.. I need to find specific files which I can do.. but I would like to be able to check subdirectories too.. the subdirectory names are not known and can change. Basically it looks for RAW image files and then calls one of our own applications to convert the raw file to a BMP and then puts them in a separate folder called BMP. But I have to do this for each folder on its own I would like to do it from the next level up and search all folders.. My Code so far is.... expandcollapse popup#include <file.au3> $search = FileFindFirstFile("*.RAW") $Count=0 ; 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 $Count = $Count + 1 WEnd ; Close the search handle FileClose($search) $qtyLeft = $Count $search = FileFindFirstFile("*.RAW") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf $File1 = " .....Searching" ProgressOn ( "Searching for files", "Please Wait" , "Found File" & $File1 ) While 1 $file1 = FileFindNextFile($search) If @error Then ExitLoop $Percent = $qtyLeft * 100 / $Count $Percent1 = 100 - $Percent ProgressSet ( $Percent1 , "Found File " & $File1 & " Files Left to search " & $qtyLeft, "Please Wait" ) ControlSetText("TitleFoo", "", "Static1", "Checking File" & $File1) $QtyLeft = $QtyLeft - 1 RunWait(@COMSPEC & " /c Raw2bmp.exe " & $File1, @SW_HIDE ) Wend ProgressSet ( 100 , "Found File " & $File1, "Completed" ) Sleep (1000) DirCreate ( "BMP" ) FileMove ( "*.BMP", "BMP" , 1 ) ProgressOff ( ) Edited August 1, 2005 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
LxP Posted August 1, 2005 Share Posted August 1, 2005 Welcome to the forums! You do not appear to specify a directory in your code. Are you currently working with files located in the same folder as the script and the converter? Link to comment Share on other sites More sharing options...
ChrisL Posted August 1, 2005 Author Share Posted August 1, 2005 (edited) Welcome to the forums!You do not appear to specify a directory in your code. Are you currently working with files located in the same folder as the script and the converter?<{POST_SNAPBACK}>Yes I am..But if I ran it from the Higher Directory level and got it to look for all sub directories then I wouldn't have to put it in every directory and run it. I cant specify a Directory name because it could be anythingEdit* Oh and Hello Edited August 1, 2005 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
LxP Posted August 1, 2005 Share Posted August 1, 2005 (edited) Alright, so would it be right to say that ideally you want to target your script on a particular folder and then have that folder, its subdirectories and their subdirectories processed?What I would first suggest is chunking the code down a bit into functions, because it will make the whole thing much easier (and in the case of folder recursion, doable).If you were to make a function called ProcessFolder(), you could have it do the following steps in order:find each .RAW file within the folder;convert each .RAW to a .BMP;create a BMP subfolder;move all .BMPs to BMP;list all subfolders;run itself (from within itself) on each subfolder.Something like this should get you started:deprecated -- read onEdit: must close search handles afterwards!Edit: d'oh, better declare the variables' scopes.Edit: incomplete filepath was used so no directory traversal. Edited August 2, 2005 by LxP Link to comment Share on other sites More sharing options...
ChrisL Posted August 1, 2005 Author Share Posted August 1, 2005 Thanks for that  [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ChrisL Posted August 2, 2005 Author Share Posted August 2, 2005 Mmmm.. it doesn't like the true or false bit func isFolder($path) if stringInStr(fileGetAttrib($path), "D") then return true return false endFunc I get an error when the sript runs.. I'm getting confused with this [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
LxP Posted August 2, 2005 Share Posted August 2, 2005 Maybe this will work better: func isFolder($path) if stringInStr(fileGetAttrib($path), "D") then return 1 return 0 endFunc Link to comment Share on other sites More sharing options...
ChrisL Posted August 2, 2005 Author Share Posted August 2, 2005 Sorry about this.. it seems to do something.. although I get an error message saying $dirs = FileFindFirstFile ("*.*")Error: Unable to open file, the maximum number of open files has been exceeded. [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
LxP Posted August 2, 2005 Share Posted August 2, 2005 Sorry -- that was dodgy coding on my part. Try the revised code above. Link to comment Share on other sites More sharing options...
ChrisL Posted August 2, 2005 Author Share Posted August 2, 2005 Sorry -- that was dodgy coding on my part. Try the revised code above.<{POST_SNAPBACK}>thats OK .. but the bad news is it still does it..If I take your code without adding anything to it.. in theory it would just go through the directory structure but not actually do anything.. Yes?It still comes up with the same error.This dirctory stuff confuses me totally.. sorry [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
LxP Posted August 2, 2005 Share Posted August 2, 2005 Sorry, this is what happens when I rush through coding... Updated above. At the moment all the code will do for each .RAW file is display its name in a message box (just added). You can pretty much copy the code from your original script into that spot with a few changes. Here's something I didn't mention before: you will probably want to do this so that the script can find the raw2bmp utility regardless of the directory it's processing. runWait(@scriptDir & '\Raw2bmp.exe "' & $path & "\" & $file & '"') Or if the utility requires DOS 8.3 filenames: $filepath = fileGetShortName($path & "\" & $file) runWait(@scriptDir & "\Raw2bmp.exe " & $filepath) Link to comment Share on other sites More sharing options...
ChrisL Posted August 2, 2005 Author Share Posted August 2, 2005 HI again.. there is still an issue.. I know this is not really fare to get you to work this out but I don't get it!! It does not do the directory thing but sits in a loop in the first working DIR, when it tries to find the next directory it doesn't.. Does that make any sense? [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
LxP Posted August 2, 2005 Share Posted August 2, 2005 (edited) Was missing a variable! Should work better now.Edit: I really should start testing my code before I upload it to threads -- I must look like a disgrace sometimes... Edited August 2, 2005 by LxP Link to comment Share on other sites More sharing options...
ChrisL Posted August 2, 2005 Author Share Posted August 2, 2005 Was missing a variable! Should work better now.Edit: I really should start testing my code before I upload it to threads -- I must look like a disgrace sometimes...<{POST_SNAPBACK}>No not likely mate.. I couldn't do it!!Will try this [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ChrisL Posted August 2, 2005 Author Share Posted August 2, 2005 Just curious.. but did you try it??? there is still something not right. Do you ever feel like you have bitten off more than you can chew??? I do! [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ChrisL Posted August 2, 2005 Author Share Posted August 2, 2005 OK.. when I put up a message box to find out what the Directory search part has found I always get \. As the loop keeps going my $Path is C:\Program Files\AutoIT3\.\.\.\.\ etc etc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
LxP Posted August 2, 2005 Share Posted August 2, 2005 (edited) I sat down and recoded it from the beginning, testing as I went along! expandcollapse popupprocessFolder(@scriptDir) func processFolder($path) local $fileHandle, $file, $dirHandle, $dir local const $FILESPEC = "*.raw" ; debug("Starting with " & $path) ; debug("Going to search for " & $path & "\" & $FILESPEC) $fileHandle = fileFindFirstFile($path & "\" & $FILESPEC) if ($fileHandle <> -1) then while (1) $file = fileFindNextFile($fileHandle) if (@error = 1) then exitLoop if ($file = "." or $file = "..") then continueLoop $file = $path & "\" & $file if (isFolder($file)) then continueLoop debug("Found file " & $file) ; here's the place to do any per-file manipulating ; $file contains the full path to the file wEnd fileClose($fileHandle) ; here's the spot to do processing on any folder that contained RAWs ; (such as making BMP subfolders and moving files) endIf ; debug("Going to search for subfolders") $dirHandle = fileFindFirstFile($path & "\*.*") if ($dirHandle <> -1) then while (1) $dir = fileFindNextFile($dirHandle) if (@error = 1) then exitLoop if ($dir = "." or $dir = "..") then continueLoop $dir = $path & "\" & $dir if (not(isFolder($dir))) then continueLoop ; debug("Found subfolder " & $dir) processFolder($dir) wEnd fileClose($dirHandle) endIf endFunc func isFolder($path) if stringInStr(fileGetAttrib($path), "D") then return 1 return 0 endFunc func debug($text) msgBox(0x40, "processFolder()", $text) endFuncEdit: added comments to the code.Edit: should work with the AutoIt release version now.Edit: copying and pasting is bad. Be careful! My main mistake before was assembling the code from within the forum page and not properly copying it to an editor for testing. This one works for me as expected -- how about you? Edited August 2, 2005 by LxP Link to comment Share on other sites More sharing options...
ChrisL Posted August 2, 2005 Author Share Posted August 2, 2005 I still get this As the loop keeps going my $Path is C:\Program Files\AutoIT3\.\.\.\.\anneheheh.raw the path just keeps increasing with .\ its like its not remembering where it got up to everytime it runs through and always goes back and finds the first dir of \. and because of this it never does any subfolders or exits.. Thanks for all of this [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
LxP Posted August 2, 2005 Share Posted August 2, 2005 (edited) I just remembered what the problem is -- it's to do with the current release of AutoIt (I was using the beta to code this solution). I should have picked that up from your last post but I was convinced that it was my evil code. I suggest grabbing a ZIP of the beta and overwriting your current release with this copy. The code above will then work as expected.Edit: or as a (probably better) alternative, I'll add two or three lines to the above code to make it compatible. Just a sec.Edit: Done now. Edited August 2, 2005 by LxP Link to comment Share on other sites More sharing options...
ChrisL Posted August 2, 2005 Author Share Posted August 2, 2005 Ahhh.. OK.. have downloaded it. It worked up to a point and then I got $dirHandle = fileFindFirstFile ($Path & "\*.*") Error unable to open file, the maximum number of open files has been exceeded But deffinately progress [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire 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