Ravenlark Posted June 20, 2006 Share Posted June 20, 2006 (edited) Alright, this being my first post to the forum, I just want to say that AutoIt is fantastic. Not only do I use it every day, but it really got me into scripting. Anyway, I am trying to create a recursive search function for a variety of different purposes; in this case to scan a hard drive and see if any files / folder are compressed. I have a working VBS script that does it, but I want to be able to do it in AutoIt for convenience. Here is the working VBS. Basically it starts at C:\, gets a list of files, checks them for compression. Gets a list of folders, checks them for compression and calls itself (so it will go through the whole filing system). The problem I am having in AutoIt is twofold; one, I cannot diffrentiate between files and folders when doing FileFindFirstFile and the subsequent FileFindNextFile. While normally a good thing, this makes performing an operation on only folders tough. Second issue. In the VBS I use the collections returned by the object.subfolders to iterate smoothly through all the files and subfolders. This is especially inportant once the recursion begins. In AutoIt, I'm not sure how to write the For Next loop. If I use an Array to store the files / folders, everything gets mucked up when the function starts calling itself. I hope what I am trying to do makes sense; with luck I am missing something obvious. Any thoughts? Thanks in advance for any ideas. Ravenlark expandcollapse popupSearchDir = "C:\" Call SystemSearch(SearchDir) Function SystemSearch([ByRef SearchDir]) '****************************************** Dim oWSHShell Dim oFSO Dim Fol Dim ThisFolder Dim Subs Dim Path Dim FL Dim FileList Dim FilePath Dim LogFile '********************************************** Set oWSHShell = WScript.CreateObject("WScript.Shell") Set oFSO = CreateObject("Scripting.FileSystemObject") Set LogFile = oFSO.OpenTextFile("C:\vbslog.txt",8,true) Set ThisFolder = oFSO.GetFolder(SearchDir) Set Subs = ThisFolder.Subfolders Set FileList = ThisFolder.Files For Each FL in FileList If FL.Attributes >= 2048 Then FilePath = FL.Path LogFile.WriteLine FL.Path LogFile.WriteLine "Compressed" Else LogFile.WriteLine FL.Path LogFile.WriteLine "NOT compressed" End If Next LogFile.Close For Each Fol in Subs Set LogFile = oFSO.OpenTextFile("C:\vbslog.txt",8,true) Path = Fol.Path SearchDir = Path If Fol.Attributes >= 2048 Then LogFile.WriteLine Fol.Path LogFile.WriteLine "Compressed" Else LogFile.WriteLine Fol.Path LogFile.WriteLine "NOT compressed" End If LogFile.Close Call SystemSearch(SearchDir) Next End Function Edited June 20, 2006 by Ravenlark Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain Link to comment Share on other sites More sharing options...
ptrex Posted June 20, 2006 Share Posted June 20, 2006 (edited) @Ravenlark expandcollapse popupDim $oWSHShell Dim $oFSO Dim $Fol Dim $ThisFolder Dim $Subs Dim $Path Dim $FL Dim $FileList Dim $FilePath Dim $LogFile Dim $SearchDir = "C:\" _SystemSearch($SearchDir) Func _SystemSearch(ByRef $SearchDir) $oFSO = ObjCreate("Scripting.FileSystemObject") $LogFile = $oFSO.OpenTextFile("C:\vbslog.txt",8,1) $ThisFolder = $oFSO.GetFolder($SearchDir) $Subs = $ThisFolder.Subfolders $FileList = $ThisFolder.Files For $FL in $FileList If $FL.Attributes >= 2048 Then $FilePath = $FL.Path $LogFile.WriteLine ($FL.Path) $LogFile.WriteLine ("Compressed") Else $LogFile.WriteLine ($FL.Path) $LogFile.WriteLine ("NOT compressed") EndIf Next $LogFile.Close () For $Fol in $Subs $LogFile = $oFSO.OpenTextFile("C:\vbslog.txt",8,1) $Path = $Fol.Path $SearchDir = $Path If $Fol.Attributes >= 2048 Then $LogFile.WriteLine ($Fol.Path) $LogFile.WriteLine ("Compressed") Else $LogFile.WriteLine ($Fol.Path) $LogFile.WriteLine ("NOT compressed") EndIf $LogFile.Close () _SystemSearch($SearchDir) Next EndFunc I hope this can help you out. Enjoy !! Edited June 20, 2006 by ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Ravenlark Posted June 20, 2006 Author Share Posted June 20, 2006 ptrex, I had no idea I could use VBS (or presumably any other WSH) code directly in AutoIt! Well looks like I was missing something obvious. Thanks for the help! Ravenlark Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain Link to comment Share on other sites More sharing options...
ptrex Posted June 20, 2006 Share Posted June 20, 2006 @Ravenlark You are welcome. Possibilities in AutoIt are 'nearly' unlimited !! Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
randallc Posted June 20, 2006 Share Posted June 20, 2006 Hi, For AutoIt answers as well, see the link in my signature to other posts. best, randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
SandelPerieanu Posted October 24, 2006 Share Posted October 24, 2006 Try this! Func FileSearch($search_dir, $s_ext = '*.*', $sep_char = @CRLF, $last_line = False) Local $allfiles = '' $search_dir = StringReplace($search_dir & '\', '\\', '\') Local $search = FileFindFirstFile($search_dir & '*.*') While 1 Local $file = FileFindNextFile($search) If $file = '' Then ExitLoop Local $full_file = $search_dir & $file Local $check_file = StringInStr(FileGetAttrib($full_file), 'D') If $check_file <> 0 Then $allfiles &= FileSearch($full_file, $s_ext, $sep_char, True) If $check_file = 0 Then If $s_ext = '*.*' Then $allfiles &= $full_file & $sep_char If $s_ext <> '*.*' And StringTrimLeft($s_ext, 1) = StringRight($full_file, StringLen(StringTrimLeft($s_ext, 1))) Then $allfiles &= $full_file & $sep_char EndIf WEnd FileClose($search) If Not $last_line Then $allfiles = StringTrimRight($allfiles, StringLen($sep_char)) Return $allfiles EndFunc ;==>FileSearch Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 24, 2006 Moderators Share Posted October 24, 2006 Try this! Func FileSearch($search_dir, $s_ext = '*.*', $sep_char = @CRLF, $last_line = False) Local $allfiles = '' $search_dir = StringReplace($search_dir & '\', '\\', '\') Local $search = FileFindFirstFile($search_dir & '*.*') While 1 Local $file = FileFindNextFile($search) If $file = '' Then ExitLoop Local $full_file = $search_dir & $file Local $check_file = StringInStr(FileGetAttrib($full_file), 'D') If $check_file <> 0 Then $allfiles &= FileSearch($full_file, $s_ext, $sep_char, True) If $check_file = 0 Then If $s_ext = '*.*' Then $allfiles &= $full_file & $sep_char If $s_ext <> '*.*' And StringTrimLeft($s_ext, 1) = StringRight($full_file, StringLen(StringTrimLeft($s_ext, 1))) Then $allfiles &= $full_file & $sep_char EndIf WEnd FileClose($search) If Not $last_line Then $allfiles = StringTrimRight($allfiles, StringLen($sep_char)) Return $allfiles EndFunc ;==>FileSearchhttp://www.autoitscript.com/forum/index.ph...c=33930&hl= Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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