beb7089 Posted January 23, 2006 Share Posted January 23, 2006 I've looked but can't seem to find a command that will allow me to search an entire drive looking for a specific file type. Ex. Finding all MP3's on C: and then piping that list to a text file. Thanks beb7089 Link to comment Share on other sites More sharing options...
BigDod Posted January 23, 2006 Share Posted January 23, 2006 I've looked but can't seem to find a command that will allow me to search an entire drive looking for a specific file type. Ex. Finding all MP3's on C: and then piping that list to a text file. Thanksbeb7089Look at the example for FileFindFirstFile in the help file. I am sure that it could be modified to write to a file. Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
rudika Posted January 23, 2006 Share Posted January 23, 2006 (edited) I've looked but can't seem to find a command that will allow me to search an entire drive looking for a specific file type. Ex. Finding all MP3's on C: and then piping that list to a text file. Thanks beb7089 try it like this $FileSourc = "c:\music\mp3" $search = FileFindFirstFile($FileSourc & "*.mp3") While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file = "." Then ElseIf $file = ".." Then sleep(10) Else FileWriteLine("C:\temp\mp3.log", $file & @CRLF) EndIf WEnd FileClose($search) Edited January 23, 2006 by rudika [font="Comic Sans Ms"][center]Powered by AutoIt3http://www.wik-eric.de/zips/Synchro2.2.2-4free.zip[/center][/font] Link to comment Share on other sites More sharing options...
strate Posted January 23, 2006 Share Posted January 23, 2006 Great, I'm making the same kinda project at home. I'll post code later. It does everything you want maybe. I have a problem of putting mp3s and movie in different spots. The "File Finder" lets you put in a extension then currently I have to select the folders to search. After it does the searching it creates a list so you can choose to copy the files to a new location or move them to the location. My problem is where you are. Having it search the whole drive instead of preselecting them. When I get home I'll post the code. INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station... Link to comment Share on other sites More sharing options...
beb7089 Posted January 23, 2006 Author Share Posted January 23, 2006 try it like this $FileSourc = "c:\music\mp3" $search = FileFindFirstFile($FileSourc & "*.mp3") While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file = "." Then ElseIf $file = ".." Then sleep(10) Else FileWriteLine("C:\temp\mp3.log", $file & @CRLF) EndIf WEnd FileClose($search) This code is great and all but.... I need the code to search every subdirectory on the C: drive. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 23, 2006 Developers Share Posted January 23, 2006 replace the msgbox with FileWriteLine....: 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:\temp" ; specify the directory to search Dim $FILEMASK="*.*" ; 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 SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
rudika Posted January 23, 2006 Share Posted January 23, 2006 (edited) This code is great and all but.... I need the code to search every subdirectory on the C: drive.I just think you wanted help, please take a look at my signatur maybe that can your wish fulfill, thank you for testing...Regards Edited January 23, 2006 by rudika [font="Comic Sans Ms"][center]Powered by AutoIt3http://www.wik-eric.de/zips/Synchro2.2.2-4free.zip[/center][/font] Link to comment Share on other sites More sharing options...
seandisanti Posted January 23, 2006 Share Posted January 23, 2006 replace the msgbox with FileWriteLine....: 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:\temp" ; specify the directory to search Dim $FILEMASK="*.*"; 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 ;==>_GetFileListhere's another recursive approach to your request... $tosearch = "C:";this is the starting directory (no ending backslash) currently hardcoded, but you could take input for this... $output = FileOpen("c:\filelist.txt",2);this is where the list is saved $start = TimerInit();this creates a filestamp when the real execution starts RecFileSearch($tosearch);this calls the function, passing the starting directory FileClose($output);once the function is done, this closes the output list MsgBox(0,"done","it only took " & int(TimerDiff($start)/1000) & " seconds");and this lets you know how long it took. Func RecFileSearch($current);the function takes a string containing the folder currently being searched, on the first call ;this would be C: or whatever path you take from input Local $search = FileFindFirstFile($current & "\*.*");creates a handle to access all files in the directory being searched While 1;infinite loop Dim $file = FileFindNextFile($search);this grabs the next file in the folder If @error Or StringLen($file)<1 Then ExitLoop;if an empty string is returned, or if the error is set because there are no more files ;the function exits If StringLower(StringRight($file,3)) = "mp3" Then FileWriteLine($output,$current & "\" & $file );this writes the filename to the list If StringInStr(FileGetAttrib($current & "\" & $file),"D") And ( $file <> "." Or $file <> ".." ) Then RecFileSearch($current & "\" & $file) ;if the file is marked as a directory, but not the . or .. directory, then the function is called for that directory WEnd;once the call from the last line (if the function called itself) returns, this loops for the next file/folder FileClose($search);once all of the folders and files have been listed, the $search handle is closed EndFunc;and the function is done. 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