Sign in to follow this  
Followers 0
suthers

differentiate dirs & files

11 posts in this topic

Hi All!

Is there a way to tell if the string returned by FileFindNextFile() represents a file name or a directory name?

shalom

Bill

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

I would imagine something like this would work:

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

[center]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.[/center]

Share this post


Link to post
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

Share this post


Link to post
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
$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

[center]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.[/center]

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

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.


[center]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.[/center]

Share this post


Link to post
Share on other sites

Well I guess I wasn't aware of it opening them. Wonder what dir does then....

I was just going to ask if you were releasing a new version soon. Good to know.

Share this post


Link to post
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...

Share this post


Link to post
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?

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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
Sign in to follow this  
Followers 0