CSP Posted July 10, 2007 Share Posted July 10, 2007 Hello I'm new to AutoIt, and I'm looking to make an app that does the following: 1. prompt for a directory location using one of those Windows built-in folder locater 2. get the name of all the files using some sort of filter(ie. *.jpg || *.avi) 3. create a file that contains the name of all the files with some more info #3 looks trivial to do using a loop to create the content and writing it out via FileOpen(). What functions should I look for in order to achieve #1 and #2? Thank you Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 10, 2007 Share Posted July 10, 2007 Hello I'm new to AutoIt, and I'm looking to make an app that does the following:1. prompt for a directory location using one of those Windows built-in folder locater2. get the name of all the files using some sort of filter(ie. *.jpg || *.avi)3. create a file that contains the name of all the files with some more info#3 looks trivial to do using a loop to create the content and writing it out via FileOpen().What functions should I look for in order to achieve #1 and #2?Thank youHi,FileSelectFolder and _FileListToArray, FileWriteFromArraySo long,Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
CSP Posted July 10, 2007 Author Share Posted July 10, 2007 FileSelectFolder and _FileListToArray, FileWriteFromArrayI looked here: http://www.autoitscript.com/autoit3/docs/functions.htm and I can't find _FileListToArray and FileWriteFromArray. Where should I look?Thank you. Link to comment Share on other sites More sharing options...
CSP Posted July 10, 2007 Author Share Posted July 10, 2007 I guess it's built-in, given that you include file.au3. Thanks. Link to comment Share on other sites More sharing options...
sshrum Posted July 11, 2007 Share Posted July 11, 2007 Here's what I use: _Array2File - writes the array to a file _FileSearch - returns a single-dim array of matching filename in a folder and subfolders if wanted. _FileDetails - takes the array returned by _FileSearch and returns a parsed pathname, size, and mod date info All you need to do is write the prompts, call these functions and your done. expandcollapse popupfunc _Array2File($aTemp, $sFilename, $iBase=1, $sSeperator="|") Consolewrite("(_Array2File) ") $iTimer = TimerInit() $iRows = ubound($aTemp) - $iBase $iCols = ubound($aTemp,2) if $iCols = 0 then $iCols = 1 ConsoleWrite("[ " & $iRows & " " & $sSeperator & " " & $iCols & " ] -> Writting '" & $sFilename & "'; ") $fOutput = FileOpen($sFilename, 2+8) FileWriteLine($fOutput, $iRows & $sSeperator & $iCols) if $iCols = 1 then For $i = $iBase to $iRows FileWriteLine($fOutput, $aTemp[$i]) next Else For $i = $iBase to $iRows $sLine = "" for $j = 0 to ($iCols - 1) if $j <> 0 AND $iCols > 1 then $sLine &= $sSeperator $sLine &= $aTemp[$i][$j] Next FileWriteLine($fOutput, $sLine) next EndIf Fileclose($fOutput) ConsoleWrite("complete [" & Round(TimerDiff($iTimer)/1000,2) & " secs]" & @CRLF) return $aTemp EndFunc func _FileDetails($aTemp) ConsoleWrite("(_FileDetails) ") $iTimer = TimerInit() ConsoleWrite("Evaluating " & $aTemp[0] & " entries...") Dim $aFiles[$aTemp[0]+1][5] $aFiles[0][0] = $aTemp[0] for $i = 1 to $aTemp[0] $aFileDate = Filegettime($aTemp[$i],0) if isarray($aFileDate) Then $sFileDate = $aFiledate[0] & "/" & $aFiledate[1] & "/" & $aFiledate[2] & " " & $aFiledate[3] & ":" & $aFiledate[4] & ":" & $aFiledate[5] Else $sFileDate = "Error" EndIf $iFileSize = FileGetSize($aTemp[$i]) $iExtPos = stringinstr($aTemp[$i], ".", 0, -1) if $iExtPos = 0 Then $sFileExt = "" Else $sFileExt = stringright($aTemp[$i], stringlen($aTemp[$i]) - $iExtPos) EndIf $sFilePath = stringleft($aTemp[$i], stringinstr($aTemp[$i], "\", 0, -1)-1) $sFileBase = stringmid($aTemp[$i], stringlen($sFilePath)+2, stringlen($aTemp[$i]) - (stringlen($sFilePath) + (stringlen($sFileext)+2))) $aFiles[$i][0] = $sFilePath $aFiles[$i][1] = $sFileBase $aFiles[$i][2] = $sFileExt $aFiles[$i][3] = Round($iFileSize/1024/1024, 2) $aFiles[$i][4] = $sFileDate Next ConsoleWrite("complete [" & Round(TimerDiff($iTimer)/1000,2) & " secs]" & @CRLF) return $aFiles EndFunc Func _FileSearch($sPath, $sQuery, $iSubdir=0, $iStripped=0) ConsoleWrite("(_FileSearch) ") $iTimer = TimerInit() $iLine = 0 $sLine = "" $aLine = "" $sPath = StringReplace($sPath & "\", "\\", "\") $iPathLen = stringlen($sPath) Dim $aFiles[100000] $aFiles[0] = 0 $sArguments = "/a-d /b /on" If $iSubDir Then $sArguments = $sArguments & " /s" ConsoleWrite('CMDLINE: dir "' & $sPath & $sQuery & '" ' & $sArguments & "...") $aRaw = Run(@ComSpec & ' /c dir "' & $sPath & $sQuery & '" ' & $sArguments, @SystemDir, @SW_HIDE, $STDOUT_CHILD) While 1 $sLine = StdoutRead($aRaw) If @error Then ExitLoop $aLine = StringSplit($SLine, @CRLF) If $aLine[0] > 1 Then For $i = 1 To $aLine[0] - 1 If $aLine[$i] = "" Then Continueloop $iLine += 1 if $iStripped <> 0 then if Stringinstr($aLine[$i], $sPath) Then $aFiles[$iLine] = stringtrimleft($aLine[$i], ($iPathLen)) Else $aFiles[$iLine] = $aLine[$i] EndIf Else $aFiles[$iLine] = $aLine[$i] EndIf Next ElseIf $aLine[0] = 1 Then If $aLine[1] = "" Then Continueloop If $aLine[1] = "File Not Found" Then Exitloop $iLine += 1 if $iStripped <> 0 then if Stringinstr($aLine[1], $sPath) Then $aFiles[$iLine] = stringtrimleft($aLine[1], ($iPathLen)) Else $aFiles[$iLine] =$aLine[1] EndIf Else $aFiles[$iLine] =$aLine[1] EndIf Else ExitLoop EndIf Wend $aFiles[0] = $iLine ReDim $aFiles[$iLine + 1] ConsoleWrite($iLine & " entries; complete [" & Round(TimerDiff($iTimer)/1000,2) & " secs]" & @CRLF) Return $aFiles EndFunc Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot' Link to comment Share on other sites More sharing options...
randallc Posted July 11, 2007 Share Posted July 11, 2007 Hi, Looks interesting, but why do I get this error? >Running AU3Check (1.54.7.0) from:C:\Program Files\AutoIt3 C:\Programs\SearchEngine\arraysearchfilesSshrum.au3(79,116) : WARNING: $STDOUT_CHILD: possibly used before declaration. $aRaw = Run(@ComSpec & ' /c dir "' & $sPath & $sQuery & '" ' & $sArguments, @SystemDir, @SW_HIDE, $STDOUT_CHILD) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~^ C:\Programs\SearchEngine\arraysearchfilesSshrum.au3(79,116) : ERROR: $STDOUT_CHILD: undeclared global variable. $aRaw = Run(@ComSpec & ' /c dir "' & $sPath & $sQuery & '" ' & $sArguments, @SystemDir, @SW_HIDE, $STDOUT_CHILD) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~^I tried; #include<array.au3> local $sPath=@ScriptDir, $sQuery="*.*", $iSubdir=0, $iStripped=0 local $ar_ArrayFiles=_FileSearch($sPath, $sQuery, $iSubdir, $iStripped) _ArrayDisplay($ar_ArrayFiles)Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 11, 2007 Share Posted July 11, 2007 (edited) Looks interesting, but why do I get this error? Add this to include the standard constants like $STDOUT_CHILD: #include <constants.au3> Edit: Or, look up the value and put that instead of the constant. The help file for Run() shows the values to ues. Edited July 11, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
sshrum Posted July 11, 2007 Share Posted July 11, 2007 I just changed the _Array2File func to create a $sMsg string first of all the array contents and then do a FileWrite instead of a FileWriteLine on each row. It was taking 30 seconds to do FileWriteLine on a 30,000 x 6 array but now takes 3 seconds doing a FileWrite. Here is the updated _Array2File func _Array2File($aTemp, $sFilename, $iBase=1, $sSeperator="|") Consolewrite("(_Array2File) ") $iTimer = TimerInit() $iRows = ubound($aTemp) - $iBase $iCols = ubound($aTemp,2) if $iCols = 0 then $iCols = 1 ConsoleWrite("[ " & $iRows & " " & $sSeperator & " " & $iCols & " ] -> Writting '" & $sFilename & "'; ") $fOutput = FileOpen($sFilename, 2+8) FileWriteLine($fOutput, $iRows & $sSeperator & $iCols) $sMsg = "" if $iCols = 1 then For $i = $iBase to $iRows $sMsg &= $aTemp[$i] & @CRLF next Else For $i = $iBase to $iRows for $j = 0 to ($iCols - 1) if $j <> 0 AND $iCols > 1 then $sMsg &= $sSeperator $sMsg &= $aTemp[$i][$j] Next $sMsg &= @CRLF next EndIf FileWrite($fOutput, $sMsg) Fileclose($fOutput) ConsoleWrite("complete [" & Round(TimerDiff($iTimer)/1000,2) & " secs]" & @CRLF) return $aTemp EndFunc Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot' Link to comment Share on other sites More sharing options...
sshrum Posted July 11, 2007 Share Posted July 11, 2007 Forgot about those pesky includes... Try it like this: #include<array.au3> #include<constants.au3> _ArrayDisplay(_FileDetails(_FileSearch(@ScriptDir, "*.*", 0, 0))) Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot' Link to comment Share on other sites More sharing options...
randallc Posted July 11, 2007 Share Posted July 11, 2007 (edited) Forgot about those pesky includes... Try it like this: #include<array.au3> #include<constants.au3> _ArrayDisplay(_FileDetails(_FileSearch(@ScriptDir, "*.*", 0, 0)))Hi, It is certainly fast, though I get different results to _FilelistToArray, which I presume (??) is accurate. 1. DOS misses lines sometimes if ANSI characters over 128; (but not always; smok-In's seems to get correct number of files, just characters read incorrectly if ANSI over 128?) 2. using PID for stdout from DOS was said to be the reason wOuter's fast DOS file count was often incorrect?; the thread there suggested it was only accurate if Window's indexing was enabled for all directories involved. i still get incorrect numbers of files even with my computer telling me indexing is on (maybe it is not??) _FileSearch, Using STD. In any case, these are the reasons I have not used DOS anymore where I could find a workaround; any thoughts? Best, randall Edited July 11, 2007 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
sshrum Posted July 12, 2007 Share Posted July 12, 2007 Haven't noticed any missing files but then again, the cmdline is looking for unhidden files (noticed that your Path was the root and query was *.*)...you can change the cmdline to include these as well and should get the same result as the other func (going out on a limb here but so far it's worked for me). Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot' 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