DoubleMcLovin Posted December 25, 2010 Share Posted December 25, 2010 (edited) I have a script that needs to determine if a file is a directory, an archive, or any regular file. So I parse the following function: Func _GetType (ByRef $target) $fAttrib = FileGetAttrib ($target) If DirGetSize ($target) > 0 Then $fType = 2 ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf If StringInStr ($fAttrib, "D") Then $fType = 2 ;Definitive check for dir ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf $arch_test = StringRegExp ($target,"(?i).*\.(rar|tar|zip)",0) ;Checks to see if file is an archive If $arch_test = 1 Then $fType = 1 ;0 means success, ftype=1 is for archives ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf If $fType = 0 Then $fType = 3 ;If its not a directory or an archive, its a file ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndFunc Even though I have a double redundancy there for directories, it continues to miss my directories and then they end up getting $fType=3. Any advice on how I can properly detect a folder? Edited December 25, 2010 by DoubleMcLovin Link to comment Share on other sites More sharing options...
guinness Posted December 25, 2010 Share Posted December 25, 2010 How about this? In your example $time & $footer weren't declared. From what I understood and from checking your example, if it was a Folder it would Return 3 when it should have been 1. ConsoleWrite(_GetType("C:\AutoIt3") & @CRLF) Func _GetType($Target) If Not FileExists($Target) Then Return SetError(1, 1, 0) ; Folder/File doesn't Exist. If StringInStr(FileGetAttrib($Target), "D") = 1 Then Return 1 ; Folder. Switch StringRegExp($Target, "(?i).*\.(rar|tar|zip)") Case 1 Return 2 ; Archive. Case Else Return 3 ; Other File. EndSwitch EndFunc ;==>_GetType UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
DoubleMcLovin Posted December 25, 2010 Author Share Posted December 25, 2010 I'm pretty sure he wants folders to return 2, but he should be able to figure out how to change that if necessary. I question the effectiveness of your archive check. Are you sure that those are the only archive type that you will encounter, or are those just the only types that you want to process? There's at least a dozen other archive types that you are not checking for. You are correct on both counts here. Directories should return "2", archives should return "1" and everything else returns "3". And I am aware there are other archives out there, but these are the only archives that I want to process. The function completes successfully btw, there is not a syntax error that I can see or autoit gripes about. And this is just one function in a long program, variables are declared earlier in the script. My problem is that even though I have the folder "tmp" in the processed directory, it tries to treat that folder as a file (gives $fType = 3). I can't understand what else I could do to determine a folder type. Guinness, I tried yours and it did the same thing. Perhaps the trouble is elsewhere in the code? Below the entirety of the script is posted. Can anyone help me find what is causing this? expandcollapse popupOpt('MustDeclareVars', 1) #include "recursive.search.functions.au3" ; #Auto Unpacker#=============================================================================================================== ; Name...........: Auto Unpacker ; Description ...: Searches set directory and unpacks files automatically ; Syntax ........: ; Parameters ....: ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: The change log readout has several characters before text. They are explained below: ; ...............: @ = Indicates a soft warning. Eg. An error that has already handled itself ; ...............: ! = Indicates an error that could not be automatically solved. ; ...............: # = Indicates a notice for a file displacement ; ...............: ^ = Indicates a file deletion ; ...............: % = Indicates a general notice ; =============================================================================================================================== ;watch dirs delineated by a "|" Local $wDir = "c:\system66\downloads\done\" Local $wDirs = StringSplit($wDir,"|") ;This is a list of words that can seperate "parts" of a files, or segments of files Local $arc_type = "rar|zip|tar" Local $arc_types = StringSplit($arc_type,"|") ;an array of different archive types Local $movie_dir = "c:\system66\media\movies\" Local $xxx_dir = "c:\system66\media\other\" Local $series_dir = "c:\system66\media\series\" Local $other_dir = "c:\system66\downloads\extracted" ;extract dir for unkown files Global $log = FileOpen (@ScriptDir & "\logs\changes.log",41) Local $file_move, $dir_move, $files, $target, $target_temp, $fName, $error, $fAttrib, $arch_test, $subfiles, $subfile Local $fType ;Used to indicate filetype. 1 = archive. 2 = directory. 3 = loose file. Global $time = @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " || " Global $footer = @TAB & "LINE: " ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: Main ; Description ...: ; Author ........: DoubleMcLovin ; Remarks .......: ; =============================================================================================================================== While 1 For $i1 = 1 to $wDirs[0] ;Cycles through watched dirs FileSetAttrib ($wDirs[$i1] & "\*","-R",1) ;Removes the Read-Only attribute. FileChangeDir ($wDirs[$i1]) $files = FileFindFirstFile ("*") While 1 $fType = 0 ; resets file type $target = FileFindNextFile ($files) ;Cycles through files in watched dirs If @error Then ExitLoop ConsoleWrite ($time & '% Now working on "' & $target & '".' & $footer & @ScriptLineNumber & @CRLF) _GetType ($target) Switch $fType Case 1 ;Archive _RenameFile ($target) _Extract ($wDirs[$i1],$target) Case 2 ;Directory _RenameDir ($target) _ExploreDir ($target) Case 3 ;File _RenameFile ($target) _PutFile ($target) EndSwitch WEnd Next FileCopy (@ScriptFullPath,@ScriptDir & "\" & @MDAY & "." & @MON & "." & @YEAR & "\" & @HOUR & @MIN & "\",9) ;backs up file every time it runs successfully. FileClose ($log) Exit WEnd ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RenameFile ; Description ...: Renames file to remove bad syntax and put all files into a standard format ; Syntax ........: _RenameFile (ByRef $target) ; Parameters ....: $target - File being renamed ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: Does so by moving the file ; =============================================================================================================================== Func _RenameFile (ByRef $target) $file_move = StringReplace (StringRegExpReplace (StringStripWS($target,8),"[-()]","."),"..",".") $error = FileMove ($target,$file_move,9) ;Moves file to rename it. Will overwrite existing file in case of duplication If Not $error = 1 Then ConsoleWrite ($time & '! "' & $target & '" cannot be moved to "' & $file_move & '". Unknown reason.' & $footer & @ScriptLineNumber & @CRLF) Else ConsoleWrite ($time & '# "' & $target & '" was moved to "' & $file_move & '".' & $footer & @ScriptLineNumber & @CRLF) EndIf $target = $file_move ;sets the new name on the file for further work EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _ExploreDir ; Description ...: Opens directories to interact with files therein ; Syntax ........: _ExploreDir (ByRef $dir_root) ; Parameters ....: $dir_root - Initial directory working in ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: None ; =============================================================================================================================== Func _ExploreDir (ByRef $dir_root) ConsoleWrite ($time & "% _ExploreDir " & $dir_root & $footer & @ScriptLineNumber & @CRLF) FileChangeDir ($dir_root) $subfiles = FileFindFirstFile ("*") If $subfiles = -1 Then ;If the dir is empty DirRemove ($dir_root) Else While 1 $subfile = FileFindNextFile ($subfiles) If @error = 1 Then Return _GetType ($subfile) Switch $fType Case 1 ;Archive _RenameFile ($target) _Extract ($wDirs[$i1],$target) Case 2 ;Directory _RenameDir ($target) _ExploreDir ($target) Case 3 ;File _RenameFile ($target) _PutFile ($target) EndSwitch WEnd EndIf EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RenameDir ; Description ...: Renames file to remove bad syntax and put all files into a standard format ; Syntax ........: _RenameDir (ByRef $target) ; Parameters ....: $target - File being renamed ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: Same as _RenameFile but with directory commands ; =============================================================================================================================== Func _RenameDir (ByRef $target) $dir_move = StringReplace (StringRegExpReplace (StringStripWS($target,8),"[-()]","."),"..",".") If FileExists ($dir_move) Then If Not $target = $dir_move Then ;Prevents deleting files that don't need to be renamed ConsoleWrite ($time & '@ "' & $target & '" cannot be moved to "' & $dir_move & '". Directory already exists. Deleting duplicate.' & $footer & @ScriptLineNumber & @CRLF) DirRemove ($target,1) EndIf Else $error = DirMove ($target,$dir_move,1) If Not $error = 1 Then ConsoleWrite ($time & '! "' & $target & '" cannot be moved to "' & $dir_move & '". Unknown reason.' & $footer & @ScriptLineNumber & @CRLF) Else ConsoleWrite ($time & '# "' & $target & '" was moved to "' & $dir_move & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf EndIf If StringRight ($dir_move,1) = "_" Then ;Removes trailing underscore from extension. This happens often for some reason DirMove ($dir_move,StringReplace ($dir_move, StringRight ($dir_move,1), "") EndIf $target = $dir_move ;sets the new name on the file for further work EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _PutFile ; Description ...: Organizes loose files ; Syntax ........: _PutFile(ByRef $target) ; Parameters ....: $target - File to be extracted ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: This function attempts to place loose files in the download directory into a directory named after themselves. ; If two or more files have similar names, they will be grouped in the same folder. Similar name is determined by removing all ; numeric characters from the name (excluding extension) for analysis. ; =============================================================================================================================== Func _PutFile (ByRef $target) ;Start by stripping name of extension and numbers $target_temp = StringRegExpReplace (StringReplace ($target,StringRight ($target,4),""),"\d","") If Not FileExists ($target_temp) Then ;Makes the directory if one doesn't exist already DirCreate ($target_temp) ConsoleWrite ($time & '# Created directory "' & $target_temp & '".' & $footer & @ScriptLineNumber & @CRLF) EndIf FileMove ($target,$target_temp) ConsoleWrite ($time & '# "' & $target & '" was moved to "' & $target_temp & '". ' & $footer & @ScriptLineNumber & @CRLF) EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _GetType ; Description ...: Gets the file type for future operations ; Syntax ........: _GetType (ByRef $target) ; Parameters ....: $target - File being analyzed ; ...............: $fType - The handle for file type variable ; Return values .: $fType = 1 Archive ; ...............: = 2 Directory ; Author ........: DoubleMcLovin ; Remarks .......: Same as _RenameFile but with directory commands ; =============================================================================================================================== Func _GetType (ByRef $target) #cs ==guinness suggested implementation== If Not FileExists($Target) Then Return SetError(1, 1, 0) ; Folder/File doesn't Exist. If StringInStr(FileGetAttrib($Target), "D") = 1 Then $fType = 2 ; Folder. ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf Switch StringRegExp($Target, "(?i).*\.(rar|tar|zip)") Case 1 $fType = 1 ; Archive. ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) Return Case Else $fType = 3 ; Other File. ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) Return EndSwitch #ce ==guinness suggested implementation== $fAttrib = FileGetAttrib ($target) If DirGetSize ($target) > 0 Then $fType = 2 ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf If StringInStr ($fAttrib, "D") Then $fType = 2 ;Definitive check for dir ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf $arch_test = StringRegExp ($target,"(?i).*\.(rar|tar|zip)",0) ;Checks to see if file is an archive If $arch_test = 1 Then $fType = 1 ;0 means success, ftype=1 is for archives ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf If $fType = 0 Then $fType = 3 ;If its not a directory or an archive, its a file ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _Extract ; Description ...: Extracts specified file ; Syntax ........: _Extract(ByRef $fDir, $target) ; Parameters ....: $fDir - Directory working in ; ...............: $target - File to be extracted ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: This function simply extracts the directed file into the done directory ; =============================================================================================================================== Func _Extract (ByRef $fDir, $target) RunWait (@ProgramFilesDir & "\winrar\winrar.exe x " & $target & " " & $fDir) ConsoleWrite ($time & "Extracted " & $target & "." & $footer & @ScriptLineNumber & @CRLF) If StringInStr ($target,"rar") Then FileDelete (StringReplace ($target, StringRight ($target,2),"")"*") ;Strips file to "file.r" and deletes all matching filter Else FileDelete ($target) EndIf ConsoleWrite ($time & '^ Deleted "' & $target & "." & $footer & @ScriptLineNumber & @CRLF) EndFunc Link to comment Share on other sites More sharing options...
KaFu Posted December 25, 2010 Share Posted December 25, 2010 A little off-topic , but here's a link to AutoUnpack which I recommend. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
DoubleMcLovin Posted December 25, 2010 Author Share Posted December 25, 2010 A little off-topic , but here's a link to AutoUnpack which I recommend.But then I would have to come up with something else to program =] Besides, unpacking is only one head of this script. Its going to manage files on my downloader/media server dynamically. Link to comment Share on other sites More sharing options...
DoubleMcLovin Posted December 25, 2010 Author Share Posted December 25, 2010 How did you get those errors? Does scite have a way to check extensively for errors? I just hit F5 to run the script each time and it exits clean. Link to comment Share on other sites More sharing options...
guinness Posted December 25, 2010 Share Posted December 25, 2010 My mistake with the Return values, but my example works With regards to your question of showing errors. If you hit Ctrl+F5 it will show the errors in the console window in SciTE. I use the full version of SciTE. Plus I have no idea how the version you posted above worked because there are syntax errors! ...Line 155 is missing ) at the end & Line 246 is missing ) at the end. Plus you have an include file of recursive.search.functions.au3 which Deathbringer and I don't have. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
DoubleMcLovin Posted December 25, 2010 Author Share Posted December 25, 2010 Ya, I haven't referenced the include file yet in this script so that's inconsequential. But I did not know about this CTRL+F5 thing. I fixed all the syntax errors shown by pressing CTRL+f5, however it is still trying to handle my directories as files! expandcollapse popupOpt('MustDeclareVars', 1) ; #Auto Unpacker#=============================================================================================================== ; Name...........: Auto Unpacker ; Description ...: Searches set directory and unpacks files automatically ; Syntax ........: ; Parameters ....: ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: The change log readout has several characters before text. They are explained below: ; ...............: @ = Indicates a soft warning. Eg. An error that has already handled itself ; ...............: ! = Indicates an error that could not be automatically solved. ; ...............: # = Indicates a notice for a file displacement ; ...............: ^ = Indicates a file deletion ; ...............: % = Indicates a general notice ; =============================================================================================================================== ;watch dirs delineated by a "|" Local $wDir = "c:\system66\downloads\done\" Local $wDirs = StringSplit($wDir,"|") ;This is a list of words that can seperate "parts" of a files, or segments of files Local $arc_type = "rar|zip|tar" Local $arc_types = StringSplit($arc_type,"|") ;an array of different archive types Local $movie_dir = "c:\system66\media\movies\" Local $xxx_dir = "c:\system66\media\other\" Local $series_dir = "c:\system66\media\series\" Local $other_dir = "c:\system66\downloads\extracted" ;extract dir for unkown files Global $log = FileOpen (@ScriptDir & "\logs\changes.log",41) Local $file_move, $dir_move, $files, $target, $target_temp, $fName, $error, $fAttrib, $arch_test, $subfiles, $subfile Local $fType ;Used to indicate filetype. 1 = archive. 2 = directory. 3 = loose file. Global $time = @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " || " Global $footer = @TAB & "LINE: " ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: Main ; Description ...: ; Author ........: DoubleMcLovin ; Remarks .......: ; =============================================================================================================================== While 1 For $i1 = 1 to $wDirs[0] ;Cycles through watched dirs FileSetAttrib ($wDirs[$i1] & "\*","-R",1) ;Removes the Read-Only attribute. FileChangeDir ($wDirs[$i1]) $files = FileFindFirstFile ("*") While 1 $fType = 0 ; resets file type $target = FileFindNextFile ($files) ;Cycles through files in watched dirs If @error Then ExitLoop ConsoleWrite ($time & '% Now working on "' & $target & '".' & $footer & @ScriptLineNumber & @CRLF) _GetType ($target) Switch $fType Case 1 ;Archive _RenameFile ($target) _Extract ($wDirs[$i1],$target) Case 2 ;Directory _RenameDir ($target) _ExploreDir ($target) Case 3 ;File _RenameFile ($target) _PutFile ($target) EndSwitch WEnd Next FileCopy (@ScriptFullPath,@ScriptDir & "\" & @MDAY & "." & @MON & "." & @YEAR & "\" & @HOUR & @MIN & "\",9) ;backs up file every time it runs successfully. FileClose ($log) Exit WEnd ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RenameFile ; Description ...: Renames file to remove bad syntax and put all files into a standard format ; Syntax ........: _RenameFile (ByRef $target) ; Parameters ....: $target - File being renamed ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: Does so by moving the file ; =============================================================================================================================== Func _RenameFile (ByRef $target) $file_move = StringReplace (StringRegExpReplace (StringStripWS($target,8),"[-()]","."),"..",".") $error = FileMove ($target,$file_move,9) ;Moves file to rename it. Will overwrite existing file in case of duplication If Not $error = 1 Then ConsoleWrite ($time & '! "' & $target & '" cannot be moved to "' & $file_move & '". Unknown reason.' & $footer & @ScriptLineNumber & @CRLF) Else ConsoleWrite ($time & '# "' & $target & '" was moved to "' & $file_move & '".' & $footer & @ScriptLineNumber & @CRLF) EndIf $target = $file_move ;sets the new name on the file for further work EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _ExploreDir ; Description ...: Opens directories to interact with files therein ; Syntax ........: _ExploreDir (ByRef $dir_root) ; Parameters ....: $dir_root - Initial directory working in ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: None ; =============================================================================================================================== Func _ExploreDir (ByRef $dir_root) ConsoleWrite ($time & "% _ExploreDir " & $dir_root & $footer & @ScriptLineNumber & @CRLF) FileChangeDir ($dir_root) $subfiles = FileFindFirstFile ("*") If $subfiles = -1 Then ;If the dir is empty DirRemove ($dir_root) Else While 1 $subfile = FileFindNextFile ($subfiles) If @error = 1 Then Return _GetType ($subfile) Switch $fType Case 1 ;Archive _RenameFile ($target) _Extract ($wDirs[$i1],$target) Case 2 ;Directory _RenameDir ($target) _ExploreDir ($target) Case 3 ;File _RenameFile ($target) _PutFile ($target) EndSwitch WEnd EndIf EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _RenameDir ; Description ...: Renames file to remove bad syntax and put all files into a standard format ; Syntax ........: _RenameDir (ByRef $target) ; Parameters ....: $target - File being renamed ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: Same as _RenameFile but with directory commands ; =============================================================================================================================== Func _RenameDir (ByRef $target) $dir_move = StringReplace (StringRegExpReplace (StringStripWS($target,8),"[-()]","."),"..",".") If FileExists ($dir_move) Then If Not $target = $dir_move Then ;Prevents deleting files that don't need to be renamed ConsoleWrite ($time & '@ "' & $target & '" cannot be moved to "' & $dir_move & '". Directory already exists. Deleting duplicate.' & $footer & @ScriptLineNumber & @CRLF) DirRemove ($target,1) EndIf Else $error = DirMove ($target,$dir_move,1) If Not $error = 1 Then ConsoleWrite ($time & '! "' & $target & '" cannot be moved to "' & $dir_move & '". Unknown reason.' & $footer & @ScriptLineNumber & @CRLF) Else ConsoleWrite ($time & '# "' & $target & '" was moved to "' & $dir_move & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf EndIf If StringRight ($dir_move,1) = "_" Then ;Removes trailing underscore from extension. This happens often for some reason DirMove ($dir_move,StringReplace ($dir_move, StringRight ($dir_move,1), "")) EndIf $target = $dir_move ;sets the new name on the file for further work EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _PutFile ; Description ...: Organizes loose files ; Syntax ........: _PutFile(ByRef $target) ; Parameters ....: $target - File to be extracted ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: This function attempts to place loose files in the download directory into a directory named after themselves. ; If two or more files have similar names, they will be grouped in the same folder. Similar name is determined by removing all ; numeric characters from the name (excluding extension) for analysis. ; =============================================================================================================================== Func _PutFile (ByRef $target) ;Start by stripping name of extension and numbers $target_temp = StringRegExpReplace (StringReplace ($target,StringRight ($target,4),""),"\d","") If Not FileExists ($target_temp) Then ;Makes the directory if one doesn't exist already DirCreate ($target_temp) ConsoleWrite ($time & '# Created directory "' & $target_temp & '".' & $footer & @ScriptLineNumber & @CRLF) EndIf FileMove ($target,$target_temp) ConsoleWrite ($time & '# "' & $target & '" was moved to "' & $target_temp & '". ' & $footer & @ScriptLineNumber & @CRLF) EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _GetType ; Description ...: Gets the file type for future operations ; Syntax ........: _GetType (ByRef $target) ; Parameters ....: $target - File being analyzed ; ...............: $fType - The handle for file type variable ; Return values .: $fType = 1 Archive ; ...............: = 2 Directory ; Author ........: DoubleMcLovin ; Remarks .......: Same as _RenameFile but with directory commands ; =============================================================================================================================== Func _GetType (ByRef $target) #cs ==guinness suggested implementation== If Not FileExists($Target) Then Return SetError(1, 1, 0) ; Folder/File doesn't Exist. If StringInStr(FileGetAttrib($Target), "D") = 1 Then $fType = 2 ; Folder. ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf Switch StringRegExp($Target, "(?i).*\.(rar|tar|zip)") Case 1 $fType = 1 ; Archive. ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) Return Case Else $fType = 3 ; Other File. ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) Return EndSwitch #ce ==guinness suggested implementation== $fAttrib = FileGetAttrib ($target) If DirGetSize ($target) > 0 Then $fType = 2 ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf If StringInStr ($fAttrib, "D") Then $fType = 2 ;Definitive check for dir ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf $arch_test = StringRegExp ($target,"(?i).*\.(rar|tar|zip)",0) ;Checks to see if file is an archive If $arch_test = 1 Then $fType = 1 ;0 means success, ftype=1 is for archives ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndIf If $fType = 0 Then $fType = 3 ;If its not a directory or an archive, its a file ConsoleWrite ($time & '% "' & $target & '" has a flag of "' & $fType & '". ' & $footer & @ScriptLineNumber & @CRLF) EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _Extract ; Description ...: Extracts specified file ; Syntax ........: _Extract(ByRef $fDir, $target) ; Parameters ....: $fDir - Directory working in ; ...............: $target - File to be extracted ; Return values .: None ; Author ........: DoubleMcLovin ; Remarks .......: This function simply extracts the directed file into the done directory ; =============================================================================================================================== Func _Extract (ByRef $fDir, $target) RunWait (@ProgramFilesDir & "\winrar\winrar.exe x " & $target & " " & $fDir) ConsoleWrite ($time & "Extracted " & $target & "." & $footer & @ScriptLineNumber & @CRLF) If StringInStr ($target,"rar") Then FileDelete (StringReplace ($target, StringRight ($target,2),"") & "*") ;Strips file to "file.r" and deletes all matching filter Else FileDelete ($target) EndIf ConsoleWrite ($time & '^ Deleted "' & $target & "." & $footer & @ScriptLineNumber & @CRLF) EndFunc Link to comment Share on other sites More sharing options...
Varian Posted December 25, 2010 Share Posted December 25, 2010 Will this suffice?Func _IsDir($Input) ;Returns 1 for Archive, 2 for Directory, 3 for File If StringRight($Input, 1) = '\' Then $Input = StringTrimRight($Input, 1) If StringInStr(FileGetAttrib($Input), 'D') <> 0 Then Return 2 Switch StringRegExp($Input, "(?i).*\.(rar|tar|zip)", 0) Case 1 Return 1 Case Else Return 3 EndSwitch EndFunc ;==>_IsDir Link to comment Share on other sites More sharing options...
guinness Posted December 25, 2010 Share Posted December 25, 2010 In the new example you know you are still using the old example and not mine or Varian's example. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
DoubleMcLovin Posted December 25, 2010 Author Share Posted December 25, 2010 Will this suffice?Func _IsDir($Input) ;Returns 1 for Archive, 2 for Directory, 3 for File If StringRight($Input, 1) = '\' Then $Input = StringTrimRight($Input, 1) If StringInStr(FileGetAttrib($Input), 'D') <> 0 Then Return 2 Switch StringRegExp($Input, "(?i).*\.(rar|tar|zip)", 0) Case 1 Return 1 Case Else Return 3 EndSwitch EndFunc ;==>_IsDir I'm afraid it is still classifying my directories as files. This function operates the same as the original function and all the others proposed. Link to comment Share on other sites More sharing options...
guinness Posted December 25, 2010 Share Posted December 25, 2010 (edited) Also I have improved the check for an "Archive File" using an example provided by Melba23 in their so a big Thanks to them Updated Version (with correct Return Values!)ConsoleWrite(_GetType("C:\AutoIt3.zip") & @CRLF) Func _GetType($Target) If Not FileExists($Target) Then Return SetError(1, 1, 0) ; Folder/File doesn't Exist. If StringInStr(FileGetAttrib($Target), "D") = 1 Then Return 2 ; Folder. Switch _IsArchive($Target, "*.RAR;*.TAR;*.ZIP") ; StringRegExp($Target, "(?i).*\.(rar|tar|zip)") Case 1 Return 1 ; Archive. Case Else Return 3 ; Other File. EndSwitch EndFunc ;==>_GetType Func _IsArchive($iFilePath, $iList = "*.RAR;*.TAR;*.ZIP") ; Based on _RFLTA_ListToMask() If StringRegExp($iList, "\\|/|:|\<|\>|\|") Then Return SetError(1, 1, 0) $iList = StringReplace(StringStripWS(StringRegExpReplace($iList, "\s*;\s*", ";"), 3), ";", "|") $iList = StringReplace(StringReplace(StringRegExpReplace($iList, "(\^|\$|\.)", "\\$1"), "?", "."), "*", ".*?") Local $iMask = "(?i)^(" & $iList & ")\z" If StringRegExp($iFilePath, $iMask) Then Return 1 Return 0 EndFunc ;==>_IsArchiveAlso why do you have you use ByRef in (ByRef $target)? Plus have you tried the Examples on their own, because this sounds like the error (or Return 3) is because the Folder doesn't exist. Edited December 25, 2010 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
DoubleMcLovin Posted December 25, 2010 Author Share Posted December 25, 2010 In the new example you know you are still using the old example and not mine or Varian's example.I have yours commented out and alternated between the two when I tried it. The examples provided all do the same as what I wrote too. All of them should work just fine from what I can see, but none are. Link to comment Share on other sites More sharing options...
guinness Posted December 25, 2010 Share Posted December 25, 2010 I was going to just say add this (see below) to check the FullName is being passed to the Function. Func _GetType (ByRef $target) MsgBox(0,"",$target) UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Varian Posted December 25, 2010 Share Posted December 25, 2010 I'm afraid it is still classifying my directories as files. This function operates the same as the original function and all the others proposed.What values are returned when you run FileGetAttrib()? I am very curious what attributes are returned on the directories which are giving you trouble. Do you have any odd Shell Extensions installed? I've never had a problem identifying directories. Link to comment Share on other sites More sharing options...
Varian Posted December 25, 2010 Share Posted December 25, 2010 (edited) I was going to just say add this (see below) to check the FullName is being passed to the Function. Func _GetType (ByRef $target) MsgBox(0,"",$target) You are very correct! I use a FileExists in my function but I took it out to suit the OP's needs. Try this:Func _IsDir($Input) ;Returns 1 for Archive, 2 for Directory, 3 for File If Not FileExists($Input) Then MsgBox(0, 'ERROR', 'Bad Input' & @LF & $Input) Return 0 EndIf If StringRight($Input, 1) = '\' Then $Input = StringTrimRight($Input, 1) If StringInStr(FileGetAttrib($Input), 'D') <> 0 Then Return 2 Switch StringRegExp($Input, "(?i).*\.(rar|tar|zip)", 0) Case 1 Return 1 Case Else Return 3 EndSwitch EndFunc ;==>_IsDir Edited December 25, 2010 by Varian Link to comment Share on other sites More sharing options...
guinness Posted December 25, 2010 Share Posted December 25, 2010 (edited) Wow, the Delete problem is Real Maybe this on Line 50 would solve the problem? And do something similar on Line 122! If StringRight($wDirs[$i1], 1) <> "\" Then $wDirs[$i1] = $wDirs[$i1] & "\" _GetType($wDirs[$i1] & $target) But use Varians Example first to confirm! You are very correct! I use a FileExists in my function but I took it out to suit the OP's needs. Try this:Me too! Edited December 25, 2010 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
DoubleMcLovin Posted December 25, 2010 Author Share Posted December 25, 2010 I see you are using FileFindNextFile. When you get a file name from that function it sets @extended to 1 if the file is a folder. Also, keep in mind that the function only returns a name, not the full path to the file. BRILLIANT! This is perfect and works great! Thanks to everyone for all the input, it still puzzles me why none of the other ideas are working, but this one-liner is absolutely perfect haha.Varian: That's just the thing, they returned a "D"! That's why I was so confused, nothing else handled the folders and a consolewrite directly afterwards showed them with the wrong $fType even though a consolewrite of the GetAttrib() showed the D. Was driving me bonkers, but using Deathbringer's solution is going to let me walk away from it.guinness: I do not know why I have ByRef for all my functions, I didn't really understand it and thought that was required to parse variables through functions. I removed them from all the functions since none of them needed it. Link to comment Share on other sites More sharing options...
guinness Posted December 25, 2010 Share Posted December 25, 2010 (edited) ByRef is useful in my opinion for Arrays (see Array.au3) when you want to "Reference" the previous variable and still use in a Local Scope.The ByRef keyword indicates the parameter should be treated as a reference to the original object. The default behavior copies the parameter into a new variable however ByRef links the new variable to the original parameter. ByRef is typically preferred when a function expects large amounts of data, such as a large array, where copying all the data would impose a significant performance penalty. Note that not only a named variable can be passed for a ByRef parameter; unnamed temporary variables, such as function return values, may be passed as ByRef parameters as well. A literal can not be passed to a ByRef parameter.Plus, Deathbringers advice makes sense! I am new at this Helping Thingy! As I myself am still learning. Edited December 25, 2010 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
DoubleMcLovin Posted December 25, 2010 Author Share Posted December 25, 2010 Yah haha, +Rep for Deathbringer on the beautiful and elegant use of something right in front of my eyes I was missing haha. 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