Jump to content

differentiate dirs & files


suthers
 Share

Recommended Posts

Directly from the helpfile: FileGetAttrib()

Returns a code string representing a file's attributes.

FileGetAttrib ( "filename" )

Parameters

filename Filename (or directory) to check.

Return Value

Success: Returns a code string representing a files attributes.

Failure: Returns "" (blank string) and sets @error to 1.

Remarks

String returned could contain a combination of these letters "RASHNDOCT":

"R" = READONLY

"A" = ARCHIVE

"S" = SYSTEM

"H" = HIDDEN

"N" = NORMAL

"D" = DIRECTORY

"O" = OFFLINE

"C" = COMPRESSED (NTFS compression, not ZIP compression)

"T" = TEMPORARY

Link to comment
Share on other sites

  • Moderators

I would imagine something like this would work:

If StringInStr(FileGetAttrib($NextFile),  'D') Then MsgBox(0, 'Director', 'File Found Is A Directory')

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

The only problem with that is it is very slow. Try this:

$test = FileFindFirstFile($path)

If $test = -1 Then
Msgbox(0,"File","The path is a file.")
Else
FileClose($test)
Msgbox(0,"Folder","The path is a folder aka directory.")
Endif

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

  • Moderators

The only problem with that is it is very slow. Try this:

$test = FileFindFirstFile($path)

If $test = -1 Then
Msgbox(0,"File","The path is a file.")
Else
FileClose($test)
Msgbox(0,"Folder","The path is a folder aka directory.")
Endif
$timer = TimerInit()
$NextFile = FileGetAttrib(@MyDocumentsDir)

If StringInStr($NextFile,  'D') Then MsgBox(0, 'It took: ' & TimerDiff($timer), 'File Found Is A Directory')
    
Sleep(2000)

$timer = TimerInit()

$test = FileFindFirstFile(@MyDocumentsDir)

If $test = -1 Then
Msgbox(0,"File","The path is a file.")
Else
FileClose($test)
Msgbox(0,'It took: ' & TimerDiff($timer),"The path is a folder aka directory.")
Endif

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

Does the FileGetAttrib function have to open the file each time? Because I really don't want to open every single file all the time.

Another thing you could do is to use the dir command in command prompt. Example: Run (@comspec & " /k dir c:\ /b /ad")

That gets all the folders on the main c drive (not recursive, that requires c:\* /s) - and keeps the window open so you can look.

Link to comment
Share on other sites

All i know is that it does open the file each time and with very large files the attributes take longer to get. Therefore, treating everything like a directory is faster when you are dealing with tons of files. I used the script i showed to optimize my older indexing engine. The speed increase when it is reading lots of files is very significant.

BTW, i am releasing a new version of my Search/Indexing Engine very soon. I used the cmd commands you told me to use green machine and i am now able to index a drive in 7 to 15 minutes.

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

  • Moderators

All i know is that it does open the file each time and with very large files the attributes take longer to get. Therefore, treating everything like a directory is faster when you are dealing with tons of files. I used the script i showed to optimize my older indexing engine. The speed increase when it is reading lots of files is very significant.

BTW, i am releasing a new version of my Search/Indexing Engine very soon. I used the cmd commands you told me to use green machine and i am now able to index a drive in 7 to 15 minutes.

I don't think my approach is the right one to be honest, I like greens approach, and in fact I liked yours for more error debugging.

I don't play with these types of things enough to really give a sound logical example, as you guys I'm sure play with them often (KandieMan especially with your recursive search script).

What I posted was just my curiousity getting the better of me.

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

I'm most interested in this

"(KandieMan especially with your recursive search script)."

If KandiMan is reading this thread, could you drop me a line on stjoeyslab at yahoo dot com?

The task I'm wanting to perform is a recursive search of a LARGE directory tree, ending up with a listing of

a) the full path+filename of every file in the tree

B) the number of characters in each full path

Shalom

Bill

(I thought enough people whold want to do this that there would already be something on the net to accomplish this, but no luck so far...

Link to comment
Share on other sites

The only problem with that is it is very slow. Try this:

$test = FileFindFirstFile($path)

If $test = -1 Then
Msgbox(0,"File","The path is a file.")
Else
FileClose($test)
Msgbox(0,"Folder","The path is a folder aka directory.")
Endif
i'm sorry, this just doesn't seem like this would DO anything... i mean the only way that FileFindFirstFile would return a -1 is if it errored. but you're saying that means that it's a file? and if there is no error close the search handle? WTF?
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...