Jump to content

FileFindFirstFile()


Recommended Posts

  • Moderators

I'm trying to allow my users to rename their .exe of my program. It is called upon by the GUI by it's name.

I was searching the Help:

FileFindFirstFile(@ProgramFilesDir & "\File1\File2\File3\" & "*.*"); Name of file they cannot currently change

The FileFindFirstFile seems would work, but it returns a "." or a ".." first then my .exe.

Any ideas on how to get rid of the "." and ".."?

Sorry if it's stupid question.

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

  • Moderators

If $result <> "." OR $result <> ".." Then

;; stuff

EndIf

<{POST_SNAPBACK}>

HA!!, I knew that!! :)

Too much 4th of July... Thanks MSLX

EDIT: Spelled your name wrong!!

Edited by ronsrules

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

  • Moderators

Ok, I stand corrected, too much 4th cheer for me. While they Bar-B-Q, I script, but I am participated in the consumption :evil: LOL.

I understood that, and thought as soon as I saw it that BINGO!!

Out of help file w/ your help.

; Shows the filenames of all files in the current directory, note that "." and ".." are returned.
$search = FileFindFirstFile(@ProgramFilesDir & "\File1\File2\File3\" & "*.*")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
If $file <> "." OR $file <> ".." Then
    MsgBox(0, "Executible is:", $file)
EndIf
WEnd

; Close the search handle
FileClose($search)

But, I'm still getting a "..", and not the executible. :)

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

Ok, I stand corrected, too much 4th cheer for me.  While they Bar-B-Q, I script, but I am participated in the consumption  :D LOL.

I understood that, and thought as soon as I saw it that BINGO!!

Out of help file w/ your help.

; Shows the filenames of all files in the current directory, note that "." and ".." are returned.
$search = FileFindFirstFile(@ProgramFilesDir & "\File1\File2\File3\" & "*.*")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
If $file <> "." OR $file <> ".." Then
    MsgBox(0, "Executible is:", $file)
EndIf
WEnd

; Close the search handle
FileClose($search)

But, I'm still getting a "..", and not the executible.  :)

<{POST_SNAPBACK}>

If $file <> "." OR $file <> ".." Then

must be

If $file <> "." AND $file <> ".." Then

too much beer in 4th :evil:

Link to comment
Share on other sites

  • Moderators

You're a beautiful man!! (I mean that in the most respectfull way (hope my wife doesn't read that :)))

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

  • Moderators

No worries m8, this "Cokes" for u!!

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

If you are looking for a .exe then why not

:; Shows the filenames of all files in the current directory, note that "." and ".." are returned.
$search = FileFindFirstFile(@ProgramFilesDir & "\File1\File2\File3\*.exe")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
   MsgBox(0, "Executible is:", $file)
EndIf
WEnd

; Close the search handle
FileClose($search)
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

  • Moderators

If you are looking for a .exe then why not

:; Shows the filenames of all files in the current directory, note that "." and ".." are returned.
$search = FileFindFirstFile(@ProgramFilesDir & "\File1\File2\File3\*.exe")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
   MsgBox(0, "Executible is:", $file)
EndIf
WEnd

; Close the search handle
FileClose($search)

<{POST_SNAPBACK}>

Because I don't want the "." or "..". Test it out yourself you'll see.

This works:

Global $Exe = Exec()

While 1
    MsgBox(4096, "File:", $Exe)
WEnd

Func Exec()
$search = FileFindFirstFile(@ProgramFilesDir & "\File1\" & "*.*")
If $search = -1 Then
   MsgBox(0, "Error", "No files/directories matched the search pattern")
   Exit
EndIf
While 1
   $Exe = FileFindNextFile($search)
   If @error Then ExitLoop
   If $Exe <> "." And $Exe <> ".." Then
         Return $Exe
   EndIf
WEnd
FileClose($search)
EndFunc

Edit: I posted this before I saw this: *.exe (I'll test that)

Edited by ronsrules

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

  • Moderators

There were a couple of syntax erros with yours buy you were right on the money too....

; Shows the filenames of all files in the current directory, note that "." and ".." are returned.
$search = FileFindFirstFile(@ProgramFilesDir & "\File1\File2\File3\*.exe")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
   MsgBox(0, "Executible is:", $file)
WEnd

; Close the search handle
FileClose($search)

Very cool... ty

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

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