Zithen Posted July 15, 2005 Share Posted July 15, 2005 have a script that some of you helped with works great, but one small problem. using ini read to see if a file has been read and if so skips that file, but for some reason it skips the first file every time with out fail, but will read the rest if there not in the ini file. here is the code any light would be good expandcollapse popup$search = FileFindFirstFile("*.txt") While 1 $numfiles = $Numfiles +1 $filename = FileFindNextFile($search) If @error Then ExitLoop $file = FileOpen($filename, 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $namearray= _arraycreate("") $matcharray = _arraycreate("") $matches = 0 $result = FileOpen("C:\Documents and Settings\grifgd\Desktop\logs\result.csv", 1) $var = IniRead($rootpath & "asset.ini","Asset Tag", $filename, "0") If $var == 0 Then ; Read in lines of text until the EOF is reached $asset = StringTrimRight($filename, 4) $ip = FileReadLine($file, 12) $ip2 = StringTrimLeft($ip, 37) $username = FileReadLine($file, 22) $username2 = StringTrimLeft($username, 12) $read = $read + 1 FileWriteLine($result, $asset & "," & $ip2 & "," & $username2) IniWrite($rootpath & "asset.ini","Asset Tag", $filename, "1") Else $skip = $skip + 1 EndIf FileClose($file) FileClose($result) $rootpath= "C:\Documents and Settings\grifgd\Desktop\logs\" $fn = $rootpath & $filename $movepath = $rootpath & "Read\*.txt" Filemove($fn, $movepath,1) WEnd PS i know the code looks like crap, but oh well lol Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2005 Moderators Share Posted July 15, 2005 (edited) I'm about to post my own question on .ini in a second, today is my first reading on it. But a quick glance at yours: $var = IniRead($rootpath & "asset.ini","Asset Tag", $filename, "0") the $filname should = "Key" name you set I believe. What ever you've decided to make "Key" in your .ini. Example: [section] = [Asset Tag] the way you have it set up and ["Key"] = ?? the way you have it So ini should look like: [Asset Tag] Key= Replace $filname with "Key" in your IniRead (this was an edit) Anyway that's the way I'm reading the .ini help today... hope it helps Edited July 15, 2005 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 More sharing options...
/dev/null Posted July 15, 2005 Share Posted July 15, 2005 (edited) using ini read to see if a file has been read and if so skips that file, but for some reason it skips the first file every time with out fail, but will read the rest if there not in the ini file.$var = IniRead($rootpath & "asset.ini","Asset Tag", $filename, "0")how is $rootpath defined before this command? If you posted the whole script, it is not defined at all. That's why IniRead fails. As far as I can see you define $rootpath at the end of the While loop. Define it at the beginning (or even better outside) and your script will work!CheersKurt Edited July 15, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Valuater Posted July 15, 2005 Share Posted July 15, 2005 (edited) your trying to read an ini file with find next file this will not work You have combined two separate file searches we worked on. One was to find files and put them in a list. The second was to read the list (if i remember correctly) your script is really a mess right now 8( Edited July 15, 2005 by Valuater Link to comment Share on other sites More sharing options...
/dev/null Posted July 15, 2005 Share Posted July 15, 2005 (edited) your trying to read an ini file. with find next file this will not workYou have combined two separate file searches we worked on. One was to find files and put them in a list. The second was to read the list (if i remember correctly)??? Did you read the script he posted ??? He lists all *.txt files. Then he reads asset.ini to check if the current file has already been read. If not, he reads in the current file and writes the content to result.csv. Then he updates asset.ini to mark the file as read. Finally he moves the processed file into another location.As I guessed, the problem is that $rootpath is not set when he first calls IniRead(), thus IniRead("" & "asset.ini","Asset Tag", $filename, "0") will return 0, as asset.ini is not found. Which in turn leads to the effect, that the frist file is skipped. After the first round, $rootpath gets set (at the end of the while loop) and the script works.EDIT: Added last sentenceCheersKurt Edited July 15, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Zithen Posted July 18, 2005 Author Share Posted July 18, 2005 sorry took so long to reply didnt have the script at home.. moved the root path to the top and still skiping the first file heres the changed code..tried a few other things but still nothing worked expandcollapse popup#include <Date.au3> #include <Array.au3> ; Shows the filenames of all files in the current directory ;DriveMapAdd("v:", "\\dcnvitm03\apps") $rootpath= "C:\Documents and Settings\grifgd\Desktop\logs" $linesread = 0 $begin = TimerInit() $numfiles = 0 $read = 0 $skip = 0 $search = FileFindFirstFile("*.txt") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $numfiles = $Numfiles +1 $filename = FileFindNextFile($search) If @error Then ExitLoop $file = FileOpen($filename, 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $namearray= _arraycreate("") $matcharray = _arraycreate("") $matches = 0 $result = FileOpen("C:\Documents and Settings\grifgd\Desktop\logs\result.csv", 1) $var = IniRead($rootpath & "asset.ini","Asset Tag", $filename, "0") If $var == 0 Then ;fileopen res ;$result = FileOpen("C:\Documents and Settings\grifgd\Desktop\logs\result.csv", 1) ; Read in lines of text until the EOF is reached $asset = StringTrimRight($filename, 4) $ip = FileReadLine($file, 12) $ip2 = StringTrimLeft($ip, 37) $username = FileReadLine($file, 22) $username2 = StringTrimLeft($username, 12) $read = $read + 1 FileWriteLine($result, $asset & "," & $ip2 & "," & $username2) IniWrite($rootpath & "asset.ini","Asset Tag", $filename, "1") Else $skip = $skip + 1 EndIf FileClose($file) FileClose($result) $rootpath= "C:\Documents and Settings\grifgd\Desktop\logs\" $fn = $rootpath & $filename $movepath = $rootpath & "Read\*.txt" Filemove($fn, $movepath,1) WEnd MsgBox(4096,"Results", "Files Read:" & $read & @CR & "Files Skiped:" & $skip) Link to comment Share on other sites More sharing options...
/dev/null Posted July 18, 2005 Share Posted July 18, 2005 sorry took so long to reply didnt have the script at home..moved the root path to the top and still skiping the first fileheres the changed code..tried a few other things but still nothing workedChange definition of $rootpath or IniRead concatenation of strings. There is no path: C:\Documents and Settings\grifgd\Desktop\logsasset.iniChange $rootpath to: $rootpath= "C:\Documents and Settings\grifgd\Desktop\logs\" ; !! TRAILING \OR change IniRead to: $var = IniRead($rootpath & "\" & "asset.ini","Asset Tag", $filename, "0")CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Zithen Posted July 18, 2005 Author Share Posted July 18, 2005 doh...**slaps head** cant belived i didnt see that, grr oh well thanks a lot Link to comment Share on other sites More sharing options...
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