Necromorph Posted February 19, 2010 Posted February 19, 2010 (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 February 19, 2010 by redLabel
dani Posted February 20, 2010 Posted February 20, 2010 (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 February 20, 2010 by d4ni
Fire Posted February 20, 2010 Posted February 20, 2010 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]
Necromorph Posted February 20, 2010 Author Posted February 20, 2010 (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 February 20, 2010 by redLabel
dani Posted February 20, 2010 Posted February 20, 2010 (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 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 February 20, 2010 by d4ni
somdcomputerguy Posted February 20, 2010 Posted February 20, 2010 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.
dani Posted February 20, 2010 Posted February 20, 2010 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.
Fire Posted February 20, 2010 Posted February 20, 2010 (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.exeOutput in my example is like this:file1.exefile2.exefile3.exe Edited February 20, 2010 by Sh3llC043r [size="5"] [/size]
Necromorph Posted February 20, 2010 Author Posted February 20, 2010 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.
dani Posted February 20, 2010 Posted February 20, 2010 Didn`t understand you d4ni.I didn`t think about the result in that case would be file1.exe file2.exe file3.exeOutput in my example is like this:file1.exefile2.exefile3.exeI meant the contents of your $read variable With FileRead you read the entire file, which as you said will holdfile1.exefile2.exefile3.exeIf 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...
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