steppedup Posted March 3, 2010 Share Posted March 3, 2010 (edited) Hi - I've googled,site googled this site, read a ton of threads, read the help files, downloaded additional files. With no luck.Is there a function somewhere that will determine if an object is a file or a directory? I will be having objects that are either files or folders - but with the same name._FileGetAttrib doesn't show any attributes for folders.Here's the desired pseudo code:Given a name of a folder or file,If IsDir Then DirCopy If IsFile Then File CopyAny help would be much appreciated!(Here's the first part of my code. If -1 == $search Then MsgBox(1,"File processing as called but was unable to match up.", "Please log on and manually process: " & $someName)EndIfWhile 1 $file = FileFindNextFile($search) If @error then ExitLoop $result = StringCompare($file, $someName) If 0== StringCompare($someName, $file) Then If StringInStr(FileGetAttrib($file), "D") > 0 ThenAnd that's where it dies, because the folder i'm testing on is not reporting back D for directory? Edited March 3, 2010 by steppedup Link to comment Share on other sites More sharing options...
jchd Posted March 3, 2010 Share Posted March 3, 2010 Answer is in the ... TADA help file, under FileFindNextFile() Success: Returns a filename according to a previous call to FileFindFirstFile, @extended set to 1 if filename is a directory. Failure: Sets @error to 1 if no more files/directories match the search. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
steppedup Posted March 3, 2010 Author Share Posted March 3, 2010 (edited) Answer is in the ... TADA help file, under FileFindNextFile() Success: Returns a filename according to a previous call to FileFindFirstFile, @extended set to 1 if filename is a directory. Failure: Sets @error to 1 if no more files/directories match the search.Thanks - I've attached my 'not smoking crack' picture proof as my help file didn't have that.Hate to bother you - but how do I return/test for the @extended set to 1?(Just finished doing some more searching on that...no luck). Edited March 3, 2010 by steppedup Link to comment Share on other sites More sharing options...
steppedup Posted March 3, 2010 Author Share Posted March 3, 2010 Thanks - I've attached my 'not smoking crack' picture proof as my help file didn't have that.Hate to bother you - but how do I return/test for the @extended set to 1?(Just finished doing some more searching on that...no luck).Just got it - sorry about the bother! Link to comment Share on other sites More sharing options...
jchd Posted March 3, 2010 Share Posted March 3, 2010 You should be using the full Scite4AutoIt3 instal plus the latest release (and even the current beta, it's working nicely). Clearly your version is outdated and doesn't offer the feature. With the new version, something like $myvar = FileFindNextFile($handle) If Not @error Then If @extended = 1 Then ; code for directory Else ; code for simple file EndIf Else ; code for no more file, e.g. ExitLoop EndIf Synapsee 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
steppedup Posted March 3, 2010 Author Share Posted March 3, 2010 You should be using the full Scite4AutoIt3 instal plus the latest release (and even the current beta, it's working nicely). Clearly your version is outdated and doesn't offer the feature. With the new version, something like $myvar = FileFindNextFile($handle) If Not @error Then If @extended = 1 Then ; code for directory Else ; code for simple file EndIf Else ; code for no more file, e.g. ExitLoop EndIf Sweet - thanks!!! Link to comment Share on other sites More sharing options...
omikron48 Posted March 3, 2010 Share Posted March 3, 2010 (edited) FYI: Directory == Folder If StringInStr(FileGetAttrib($filename)), "D") Then ;DirCopy Else ;FileCopy EndIf Edited March 3, 2010 by omikron48 Link to comment Share on other sites More sharing options...
steppedup Posted March 4, 2010 Author Share Posted March 4, 2010 FYI: Directory == Folder If StringInStr(FileGetAttrib($filename)), "D") Then ;DirCopy Else ;FileCopy EndIf That was the first thing I tried. For some weird reason, I was getting "" returned on a test folder. All good with the above solution though - thanks! Link to comment Share on other sites More sharing options...
MHz Posted March 4, 2010 Share Posted March 4, 2010 That was the first thing I tried. For some weird reason, I was getting "" returned on a test folder. All good with the above solution though - thanks! And let me tell you why your code failed. You did not show the FileFindFirstFile() pattern but I am going to guess that it was not in the current working directory. Look at this example: $search = FileFindFirstFile(@WindowsDir & '\*') If -1 == $search Then MsgBox(1,"File processing as called but was unable to match up.", "Please log on and manually process: "); & $someName) EndIf While 1 $file = FileFindNextFile($search) If @error then ExitLoop ;~ $result = StringCompare($file, $someName) ;~ If 0== StringCompare($someName, $file) Then If StringInStr(FileGetAttrib(@WindowsDir & '\' & $file), "D") > 0 Then MsgBox(0, @WorkingDir, @WindowsDir & '\' & $file & ' is a directory') EndIf If StringInStr(FileGetAttrib($file), "D") > 0 Then MsgBox(0, @WorkingDir, $file & ' is a directory') EndIf WEnd The 1st instance of FileGetAttrib() uses a full path to the filename used by FileFindFirstFile() and the 2nd instance of FileGetAttrib() uses just a filename. Which occurrence of FileGetAttrib() will succeed? I am betting on the 1st instance as FileGetAttrib() knows where the filename is as the path is supplied to it. FileFindNextFile() returns just the filename so if it is not in the current working directory then you may need to tell the other file handling functions in the loop where the filename is located. BTW, the > 0 used on StringIsStr is unneeded as StringIsStr can be treated as a boolean (True/False condition). 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