Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading from files and formatting text

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
US
I need to watch for files in a specific directory on our company LAN. When a new file arrives, I need to open it for reading and format the text and then FTP the file and SMTP a message.

I have the FTP and SMTP part under control, but I am unable to get the file to open and format the text.

Does anyone know how to automatically open a file for reading and writing and then format the text?

Thanks.
Mindy
 
How about putting a timer component in. Then every few minutes you could do check to see if the file is there via FileExists. If the file exists, then you can do whatever you need to. You could also put this on its own thread so it doesn't tie up your app. James P. Cottingham
 
James -

The only problem is I will have no way of knowing what the actual name of the file will be. It can be anything. I want to open and format the text in ALL files that come into the directory.

I am sure that all files in the directory will be text files.

Also, since I am a relative newbie....how can i put it on its own thread? Can you explain that to me?

Thanks.

Mindy
 
OK. This is a little more complex. What you need to do is periodically (with a timer) look through the directory using findfirst (or FindFirst) and findnext (or FindNext). Look at thread101-49144 and thread101-65770. (Note that in these threads, he is looking through all directories on a drive and you only need to look at one directory.) Once a file has been found, you can parse it, etc. Question: why do you need to open the file for both reading and writing?

As far as using threaded programming, it depends on how you impliment your program. For example, if your program is only going to look for files then format and send them, you don't need multithreading since each program in Windows starts with its own thread. In this case, you can just make the program minimize or run in the system tray.

If your program is going to be doing other things at the same time, you should use threads. Look at the TThread component. Once you have decided how to proceed, post back here for details.
James P. Cottingham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top