Jump to content

Help with FileFindFirstFile & FileOpen


ttleser
 Share

Recommended Posts

Need some help as to why this isn't working properly. In the directory "\\192.168.100.1\c$\test" I've got many files, many what start with "T", I'm just interested in one file that'll start with TA. This TA file will probably have a file name of TA144.txt where if you look in the file at the end of the very first line of the file will be the version of the program 1.44. I'm looking to have the script read the file and tell me what the last 4 characters of the first line will be. Now, the filename might be TA145.txt if it's a newer version, and so on. So I need to be able to account for different file names, all of which will always have the version IN the file. Listed below is a simplified version of my script:

$search = FileFindFirstFile("\\192.168.100.1\c$\test\ta*.txt")
$filename = FileFindNextFile($search)
msgbox(0,"filename",$filename)
$file = FileOpen($filename, 0)
;$file = FileOpen("\\192.168.100.1\c$\test\ta*.txt",0)
msgbox(0,"file",$file)
$line = FileReadLine($file)
$output = StringRight($line, 4)
msgbox(0,"line",$output)
oÝ÷ Øé-êk¡¹^ý¯x0Ømæ¢÷¬r¸©¶+-«b·lky§bayø¥xn¶)æ²èÆË(¶­!Ƨ±ç°«mêÞ²ém²ÞiÈh~Ø^½ªâi¹^±ªÞêÞ­¶²±¬²èÆ«¨µø¥zv¦z«¨·¥Æ²ªê-L
xâÜmªê-2È£®¢×âꮢÜ"[Ê«¨·Z®¢Ó,º1ªê-)Þªê-Â)e±¬ªºjº[©ä6r§çmë®*m²X Ùr¶{Z·lq«¬x-êk¡¹^«­¢+Ø(ÀÌØíÍÉ ô¥±¥¹¥ÉÍÑ¥± ÅÕ½ÐìÀäÈìÀäÈìÄäȸÄØà¸ÄÀÀ¸ÄÀäÈíÀÌØìÀäÈíÑÍÐÀäÈíѨ¹ÑáÐÅÕ½Ðì¤(ÀÌØí¥±¹µô¥±¥¹9áÑ¥± ÀÌØíÍÉ ¤)µÍ½à À°ÅÕ½Ðí¥±¹µÅÕ½Ðì°ÀÌØí¥±¹µ¤(ìÀÌØí¥±ô¥±=Á¸ ÀÌØí¥±¹µ°À¤(ÀÌØí¥±ô¥±=Á¸ ÅÕ½ÐìÀäÈìÀäÈìÄäȸÄØà¸ÄÀÀ¸ÄÀäÈíÀÌØìÀäÈíÑÍÐÀäÈíÑÄÐйÑáÐÅÕ½Ðì°À¤)µÍ½à À°ÅÕ½Ðí¥±ÅÕ½Ðì°ÀÌØí¥±¤(ÀÌØí±¥¹ô¥±I1¥¹ ÀÌØí¥±¤(ÀÌØí½ÕÑÁÕÐôMÑÉ¥¹I¥¡Ð ÀÌØí±¥¹°Ð¤)µÍ½à À°ÅÕ½Ðí±¥¹ÅÕ½Ðì°ÀÌØí½ÕÑÁÕФ

The problem appears to be the FileFindNextFile search function working with the fileopen function. Here's the result of the msgboxs:

Msgbox "filename" will say "TA144.txt"

Msgbox "file" will say "2"

Msgbox "line" will say "1.44"

Link to comment
Share on other sites

First I'd like to say thanks for experimenting and testing before you actually post a question, that's the best way you learn. Moving on, based upon your last results:

Msgbox "filename" will say "TA144.txt"

Msgbox "file" will say "2"

Msgbox "line" will say "1.44"

The Msgbox for the filename and the Msgbox for the line succeeded. The "file" Msgbox was 2, but that's perfectly normal since what exactly does FileOpen return? A number used to see if the function succeeded or failed. So look up in the helpfile FileOpen and look at what it returns.

Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

I did look in the help file.

Take a look at the first script I posted as that's the one I need working. Script #2 was modification to see where the problem lies. Unfortunately script #2 doesn't allow for searching for a filename, but instead relies on the exact filename.

Link to comment
Share on other sites

You don't necessarily need a FileOpen to perform a FileRead, have you considered using something like this:

$line = FileReadLine($file, 1)
;Or
$line = FileRead($file)

Unfortunately I am not currently on my home computer to give you more accurate advice, hope it works :)

Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

Perhaps try this, I came up with it quickly and it may contain errors since I do not have autoit here.

Local $path = "\\192.168.100.1\c$\test\"
$search = FileFindFirstFile($path & "ta*.txt")
$filename = FileFindNextFile($search)
$new = $path & $filename
$read = FileRead($new)         ;$read now contains the text in the file
$output = StringRight($read, 4)

Hope it works :)

Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

192.168.100.1 looks like a network address, not like a host address. Are you sure this is the correct address of the host? In many cases, this network address is used by cable modems and such. Are you trying to access a modem or router? A host address doesn't have a 1 in the fourth octet that i am aware of.

Edited by The Kandie Man

"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

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