Clay Posted May 30, 2008 Posted May 30, 2008 (edited) Hey guys, Quick question. I am using FileGetShortName to extract the name of a random file that always start with APE... I am using the following code but can't seem to capture the file. The problem is with this line $tmp = FileFindFirstFile(FileGetShortName(@ScriptDir)&"APE\*") with this being the specific problem .......FileGetShortName(@ScriptDir)&"APE\*") Does anyone know how to format FileGetShortName to return a string the always starts with APE but is following by a random sequence of strings? Here is the full snippet #include <file.au3> $tmp = FileFindFirstFile(FileGetShortName(@ScriptDir)&"APE\*") $LogName = FileFindNextFile($tmp ) MsgBox(0, "", $LogName) $CountLines = _FileCountLines($LogName) MsgBox(64, "Error log recordcount", "There are " & $CountLines & " in the error.log.") Exit Edited May 30, 2008 by Clay
monoceres Posted May 30, 2008 Posted May 30, 2008 (edited) Hi! Maybe this works for you? #include <file.au3> $array=_FileListToArray(@Scriptdir,"APE*") If IsArray($array) Then $file=@ScriptDir&"\"&$array[Random(1,Ubound($array)-1,1)] MsgBox(0,"Random APE file",FileGetShortName($file)) EndIf Edited May 30, 2008 by monoceres Broken link? PM me and I'll send you the file!
Clay Posted May 30, 2008 Author Posted May 30, 2008 (edited) Doesn't do exactly what I want. In this isntance the name of the File is APE_CRITICAL_ERRORS_FMAS_2008-05-30 I want to be able to get just the name of that file not the entire system root directory ..... I want to be able to do some operations with the file and with the entire path it is not much help to me. But thanks for your input... any other suggestions? Edited May 30, 2008 by Clay
GEOSoft Posted May 30, 2008 Posted May 30, 2008 Try removing the FileGetShortName from FileGetFirstFile() and put it into FileGetNextFile() instead. I don't have AutoIt on the computer I'm using at the moment so I can't test it. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Clay Posted May 30, 2008 Author Posted May 30, 2008 Try removing the FileGetShortName from FileGetFirstFile() and put it into FileGetNextFile() instead.I don't have AutoIt on the computer I'm using at the moment so I can't test it.I've tried that but tried it again nontheless but with no success...... thanks anyways, I aprpeciate you trying to help me even if you don't have Autoit Installed at the moment.
someone Posted May 30, 2008 Posted May 30, 2008 (edited) From your original description I'm confused why your using FileGetShortName at all... try this; $search = FileFindFirstFile("APE*") ;searches for any file starting with APE in same directory as script ; 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(4096, "File:", $file) WEnd ; Close the search handle FileClose($search) Edited May 30, 2008 by someone While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
Clay Posted May 30, 2008 Author Posted May 30, 2008 From your original description I'm confused why your using FileGetShortName at all... try this; $search = FileFindFirstFile("APE*") ;searches for any file starting with APE in same directory as script ; 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(4096, "File:", $file) WEnd ; Close the search handle FileClose($search) Someone ...who ever you are, You were right ... I was using the function wrong. I confused the outcome of what I was trying to get with other uses of the function that I had previously implemented. Thanks for the correction. It worked. I have what I need now...I think :<
GEOSoft Posted May 30, 2008 Posted May 30, 2008 Just laying here thinking about it and I realized what is wrong. #include <file.au3> $tmp = FileFindFirstFile(@ScriptDir & "\APE\*") $LogName = FileGetShortName(FileFindNextFile($tmp )) MsgBox(0, "", $LogName) $CountLines = _FileCountLines($LogName) MsgBox(64, "Error log recordcount", "There are " & $CountLines & " in the error.log.") Exit You did not show how you intend to randomize it so this may need some modification. You are not randomizing by using "*". That's just a wildcard that says get any file. and because you don't have a loop after FileFindNextFile Then it will only return the first file found even if it is actualy a folder. What was wrong with the random example you were given by monoceres? George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Clay Posted May 30, 2008 Author Posted May 30, 2008 (edited) Just laying here thinking about it and I realized what is wrong. #include <file.au3> $tmp = FileFindFirstFile(@ScriptDir & "\APE\*") $LogName = FileGetShortName(FileFindNextFile($tmp )) MsgBox(0, "", $LogName) $CountLines = _FileCountLines($LogName) MsgBox(64, "Error log recordcount", "There are " & $CountLines & " in the error.log.") Exit You did not show how you intend to randomize it so this may need some modification. You are not randomizing by using "*". That's just a wildcard that says get any file. and because you don't have a loop after FileFindNextFile Then it will only return the first file found even if it is actualy a folder. What was wrong with the random example you were given by monoceres? GEO, This is the scoop. I am working on a project where I am creating installation files for probably 80 products.... to test that the installations are configured properly I use this huge script that I have built to run through everything and do Sanity Test. I have two log files that are the output of the script... one is a log with all the processes that the script completed, the other is one that list erros, and critical warnings about things that are not working properly. I only want to be notified of the critical stuff (since there are like 80 products, I dont want to have to go through all the log files for all the products at this point)... The log containing the critical stuff will only show up if a critical error occured. If one does occur and I do have errors, on the script exit I want it to complete a few operations on the Critical log file and then send me an email notifying me of the critical stuff that I need to fix... Thats why I wanted to check the particular folder for a log file starting with APE.... the files would be APE_AA_BBB_ProductA.log APE_AA_BBB_ProductB.log for example. The function to do this turned out to be really simple... I just had a problem with FileFindFirstFile The completed function looks like this Func logVaild() ;searches for any file starting with APE in same directory as script $tmp = FileFindFirstFile(@ScriptDir & "APE_Logs\APE*") ; Check if the search was successful If $tmp = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf $LogName = FileFindNextFile($tmp ) $CountLines = _FileCountLines($LogName) ******MORE CODE HERE ******MORE CODE HERE FileClose($tmp) Exit EndFunc monoceres solution gave me something to the extent C:\.......APE_Logs\APE~1.log Thanks all you guys for you help Edited May 30, 2008 by Clay
GEOSoft Posted May 30, 2008 Posted May 30, 2008 Understood. Because of the \ before APE, I assumed APE was a folder. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
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