Sign in to follow this  
Followers 0
Zithen

reading files

9 posts in this topic

looking to see how to do the following:

have a script that pulls thourgh a buch of text files pulls some information out into a .csv file. unfortently i cant just move the files after i have read them, they have to stay where they are. is there/how can i make it so that it can check to see if that file has been read already so not to reread the file and reenter the data?

Share this post


Link to post
Share on other sites



wanted to give a little more information on the csv file. it pulls 2 things from the file ipaddress and username, and gets computer name from the filename with a trim to cut .txt off since thats how it saves and looks like this

computername,ipaddress,username

Share this post


Link to post
Share on other sites

You could read the names of the files into an array and then process each element of that array. Because each name would only occur once, you would never read any file twice.

Share this post


Link to post
Share on other sites

looking to see how to do the following:

have a script that pulls thourgh a buch of text files pulls some information out into a .csv file. unfortently i cant just move the files after i have read them, they have to stay where they are. is there/how can i make it so that it can check to see if that file has been read already so not to reread the file and reenter the data?

<{POST_SNAPBACK}>

How do you get the list of files to be processed? FileFindNextFile will never return the same file on a single search handle.

Share this post


Link to post
Share on other sites

i really need to think more clearly when i post things i left out the main part....

and i can get it to read the files all fine, but this is the part i missed, there are new files that will be comming in so i will need to run the script agine to get the infomration off the new files, currently if i rerun the script it will add all the files agine, i just want to get the stuff off the new files and skip the ones that were read before.

Share this post


Link to post
Share on other sites

Alternatively you could use the registry, an INI file or even just a plain text file to keep track of the files that have been processed. A plain text file would probably be best for the job because it would be easiest to manipulate.

All you would need to do is search this list file for the name of the file to be processed, and if the file isn't listed then process it and append the name of that file to the end of the list.

Share this post


Link to post
Share on other sites

Alternatively you could use the registry, an INI file or even just a plain text file to keep track of the files that have been processed. A plain text file would probably be best for the job because it would be easiest to manipulate.

All you would need to do is search this list file for the name of the file to be processed, and if the file isn't listed then process it and append the name of that file to the end of the list.

<{POST_SNAPBACK}>

If you went this route, you could use my binary trees UDF to quickly keep a list of which files are done, and check to see if you've hit a file already or not.

I think it would be easier to write a function that would store the time/date in a global variable, then loop through all the files. If the file date is newer than the last time the function ran, then obviously it's a new file.

There are also ways (through DLL calls) to set a hook into a directory that you can check to see if any file has changed, but I don't know the calls off-hand.

Share this post


Link to post
Share on other sites

How about using FileSetAttrib to mark the files you've processed?

Or even better :evil: .. you can setup an INI file, where the file names that you process form the parameter-names: at first, the INI is empty, and when you read your first file, you check the INI to see if it's there .. which it isn't, as indicated by the default value from IniRead. So you process it, and then use IniWrite to add the filename as a parameter to the INI file.

If you set the parameter values equal to the date and time of using the IniWrite, then you get extra statistical value from the INI file .. for free :)

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