Sign in to follow this  
Followers 0
Necromorph

$var help

10 posts in this topic

#1 ·  Posted (edited)

im try to find a way to read a file name and set that to a $var so i can input it later. but the file name will change as time goes on, so i need the $var to be assigned every time i run the script

so i need like

$installerver=FILEREAD(@DESKTOPDIR & "TestFile-*.exe")

then later

CONTROLSETTEXT ("TITLE", "TEXT", "[CONTROL ID]", $installerver)

but Im not sure how to code this exactly

Please help the NOOB, lol

Thanks in advanced

Edited by redLabel

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here you go:

FileChangeDir(@DesktopDir)
$hSearch = FileFindFirstFile("*.exe")
$fileName = FileFindNextFile($hSearch)
FileClose($hSearch)

Remember this just gives you the filename of the first .exe file it encounters -- based on alphabetical order I believe. You could edit the wildcard ("*.exe") if you have more information about the filename. For example, if it always ends with 'Server.exe' you can edit the wildcard to "*Server.exe".

~ edit

added FileClose($hSearch)

Edited by d4ni

Share this post


Link to post
Share on other sites

You can try this way too.

Run("notepad.exe")
WinWait("[CLASS:Notepad]")
RunWait("cmd.exe /c " & "dir /B fi*.exe >>" &@TempDir&"\list.txt",@ScriptDir,@SW_HIDE) ;in cur dir for fi*.exe files
$read=FileRead(@TempDir&"\list.txt")
ControlSetText("[CLASS:Notepad]", "", "", $read)
FileDelete(@TempDir&"\list.txt")

[size="5"] [/size]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

this will probably work but, (d4ni)

my code calls a new install package everytime it runs, so i always have the latest installer (i test software)

so for a while it would be "installer-0.25.exe"

then it would be "installer-0.26.exe"

and so on and so forth

so i want to call it as "installer-*.exe"

so some how i need to read name of the specific installer that im coping to the DESKTOPDIR and assign that to a $var

so it needs to be like (i know this isn't a command but it would be perfect)

$installerver=FILEGETNAME("INSTALLER-*.exe")

or something similar

or maybe

can i do this?

FILECHANGEDIR(@DESKTOPDIR)

$installver=FILECOPY("DIR\installer-*.exe", "installer-*.exe")

Edited by redLabel

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@Sh3llC043r

That seems very complicated while the result is comparable to mine. However, when there are more .exe files matching it won't give you the first result, it will give you a string like "file1.exe file2.exe file3.exe" which is not usable, although you could call StringSplit on it...

@redLabel

Can't you get it to work with the code either I or Sh3llC043r provided? Seems like you have all the functions you need. Maybe I don't completely understand what you want. Honestly, it seems like you didn't really read my first reply :mellow:

so it needs to be like (i know this isn't a command but it would be perfect)

$installerver=FILEGETNAME("INSTALLER-*.exe")

You can do this by using my first reply and changing the wildcard, as I already stated in that reply:

FileChangeDir(@DesktopDir)
$hSearch = FileFindFirstFile("INSTALLER-*.exe")
$fileName = FileFindNextFile($hSearch)
Edited by d4ni

Share this post


Link to post
Share on other sites

This example was mostly copied/pasted from the help file. I haven't tested to see if it works, but it probably does..

$search = FileFindFirstFile("TestFile-*.exe")  

If $search = -1 Then
    MsgBox(0, "Error", "No files match the search pattern")
    Exit
EndIf

While 1
    $installerver = FileFindNextFile($search)
    If @error Then ExitLoop
   
    MsgBox(4096, "File:", $installerver)
WEnd
FileClose($search)

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

It would be nice if people first read the existing comments, lol. Snowmaker; that's pretty much what I posted, I just forgot the FileClose command. The loops are fun and all but not required in this case. Also, you don't search @DesktopDir but @ScriptDir.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

That seems very complicated while the result is comparable to mine. However, when there are more .exe files matching it won't give you the first result, it will give you a string like "file1.exe file2.exe file3.exe" which is not usable, although you could call StringSplit on it...

Didn`t understand you d4ni.

I didn`t think about the result in that case would be file1.exe file2.exe file3.exe

Output in my example is like this:

file1.exe

file2.exe

file3.exe

Edited by Sh3llC043r

[size="5"] [/size]

Share this post


Link to post
Share on other sites

Thanks for all the replies guys.

They both do work so thanks a lot, i have some options to play with

and i forgot that when i

FILECOPY("DIR", "installer-*.exe", 1)

its gonna overwrite the (1) the previous wildcard version, so it will always be first in the FILEFINDFIRSTFILE.

so its perfect. thanks again.

Share this post


Link to post
Share on other sites

Didn`t understand you d4ni.

I didn`t think about the result in that case would be file1.exe file2.exe file3.exe

Output in my example is like this:

file1.exe

file2.exe

file3.exe

I meant the contents of your $read variable :mellow: With FileRead you read the entire file, which as you said will hold

file1.exe

file2.exe

file3.exe

If this is put into a string, the string will be like file1.exe\nfile2.exe\nfile3.exe -- or something similar where \n represents the line end character.. Thus, that variable is not usable directly...

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