Jump to content

IsDir


Recommended Posts

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 Copy

Any 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)

EndIf

While 1

$file = FileFindNextFile($search)

If @error then ExitLoop

$result = StringCompare($file, $someName)

If 0== StringCompare($someName, $file) Then

If StringInStr(FileGetAttrib($file), "D") > 0 Then

And that's where it dies, because the folder i'm testing on is not reporting back D for directory?

Edited by steppedup
Link to comment
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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

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 by steppedup
Link to comment
Share on other sites

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

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

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 here
RegExp tutorial: enough to get started
PCRE 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

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

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).

:mellow:

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...