suthers Posted January 18, 2006 Share Posted January 18, 2006 Hi All! Is there a way to tell if the string returned by FileFindNextFile() represents a file name or a directory name? shalom Bill Link to comment Share on other sites More sharing options...
greenmachine Posted January 18, 2006 Share Posted January 18, 2006 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 More sharing options...
Moderators SmOke_N Posted January 18, 2006 Moderators Share Posted January 18, 2006 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 More sharing options...
The Kandie Man Posted January 18, 2006 Share Posted January 18, 2006 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 More sharing options...
Moderators SmOke_N Posted January 18, 2006 Moderators Share Posted January 18, 2006 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 More sharing options...
greenmachine Posted January 18, 2006 Share Posted January 18, 2006 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 More sharing options...
The Kandie Man Posted January 18, 2006 Share Posted January 18, 2006 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 More sharing options...
Moderators SmOke_N Posted January 18, 2006 Moderators Share Posted January 18, 2006 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 More sharing options...
greenmachine Posted January 18, 2006 Share Posted January 18, 2006 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. Link to comment Share on other sites More sharing options...
suthers Posted January 18, 2006 Author Share Posted January 18, 2006 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 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 More sharing options...
seandisanti Posted January 18, 2006 Share Posted January 18, 2006 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 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