Skizmata Posted September 18, 2009 Share Posted September 18, 2009 How would you make a IsDirectory() function in AutoIt. Perl sub example... sub IsDirectory() { $target = shift(); return 1 if (-d $target); return 0; } AutoIt changed my life. Link to comment Share on other sites More sharing options...
Mat Posted September 18, 2009 Share Posted September 18, 2009 MsgBox (0, "Test results", _IsDirectory ("c:\")) Func _IsDirectory ($sDir) If StringInStr (FileGetAttrib ($sDir), "D") Then Return 1 Return 0 EndFunc ; ==> _IsDirectory Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 18, 2009 Moderators Share Posted September 18, 2009 Func _IsDirectory($s_file) Return StringInStr(FileGetAttrib($s_file), "D") EndFunc 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...
Skizmata Posted September 18, 2009 Author Share Posted September 18, 2009 Thanks guys! Perfect! AutoIt changed my life. Link to comment Share on other sites More sharing options...
Mat Posted September 18, 2009 Share Posted September 18, 2009 Func _IsDirectory($s_file) Return StringInStr(FileGetAttrib($s_file), "D") EndFunc Very close to mine! The only diffrence is that yours will return the offset of the letter D, which should be 3? A better Idea would be to do this: Func _IsDirectory ($sDir) Return StringInStr (FileGetAttrib ($sDir), "D") <> 0 EndFunc ; ==> _IsDirectory Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 18, 2009 Moderators Share Posted September 18, 2009 Very close to mine! The only diffrence is that yours will return the offset of the letter D, which should be 3? A better Idea would be to do this: Func _IsDirectory ($sDir) Return StringInStr (FileGetAttrib ($sDir), "D") <> 0 EndFunc ; ==> _IsDirectory Mat If you want a boolean return sure. But as far as "Better", not quite sure where that comes into play. 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...
Mat Posted September 18, 2009 Share Posted September 18, 2009 As said, you are returning the offset. If you want 1 or 0, not bool then use my first script (or in one line:) Func _IsDirectory ($sDir) Return StringRegExp (FileGetAttrib ($sDir), "D", 0) EndFunc ; ==> _IsDirectory That way it will not return 3. Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Yashied Posted September 18, 2009 Share Posted September 18, 2009 Func _IsDirectory($sDir) Local $Ret = DllCall('shlwapi.dll', 'int', 'PathIsDirectoryW', 'wstr', $sDir) Return $Ret[0] EndFunc ;==>_IsDirectory Returns 16 (TRUE) or 0 (FALSE). My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
marc0v Posted September 18, 2009 Share Posted September 18, 2009 Additionnally _IsFile (not a directory but really a file) Func _IsFile ($sFile) Return Not(StringRegExp (FileGetAttrib ($sFile), "D", 0)) EndFunc ; ==> _IsFile This return a boolean (true/false) OR Func _IsFile ($sFile) Return Not(StringRegExp (FileGetAttrib ($sFile), "D", 0)) + 0 EndFunc ; ==> _IsFile This return a number (0(is not a file)/1(is a file)) I can't really test since I use v3.2.0.1 and I don't have StringRegExp but it should work 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