944,218 Members | Top Members by Rank

Ad:
Jun 11th, 2007
0

Verifying the existence of a file with a delphi program.

Expand Post »
I've been working on a program designed to allow the end user to offer data corrections back to my company. (That is, they send us the originals, we process those and store it in a database, and this program is supposed to allow them to search the DB and send us back a file with any changes that need to be made.)

The sending back of a file is the part where I'm asking for assistance. At the moment, I can correctly write the file out to the necessary network location. However, I'd like to be able to add an error message if something happens to the file during transmission. At the moment, the only thing I can think of is try to have the program find the filename at the target location, and I'm trying to come up with a way to do that. I've found some stuff about a 'TFileFind' on google, and I'm continuing to follow that up, but I was wondering about what other, possibly simpler, methods exist to simply verify the existence of a file from within a delphi program.

Hopefully that largish paragraph made sense...anyone have any suggestions for alternative paths to my goal?

Thanks.
Similar Threads
Reputation Points: 483
Solved Threads: 1
Posting Shark
EnderX is offline Offline
999 posts
since Aug 2006
Jun 12th, 2007
1

Re: Verifying the existence of a file with a delphi program.

this is from delphi's help:

the following example uses an edit control, a button, a string grid, and seven check boxes. The check boxes correspond to the seven possible file attributes. When the button is clicked, the path specified in the edit control is searched for files matching the checked file attributes. The names and sizes of the matching files are inserted into the string grid.

procedure TForm1.Button1Click(Sender: TObject);

var
sr: TSearchRec;
FileAttrs: Integer;
begin
StringGrid1.RowCount := 1;
if CheckBox1.Checked then
FileAttrs := faReadOnly
else
FileAttrs := 0;
if CheckBox2.Checked then
FileAttrs := FileAttrs + faHidden;
if CheckBox3.Checked then
FileAttrs := FileAttrs + faSysFile;
if CheckBox4.Checked then
FileAttrs := FileAttrs + faVolumeID;
if CheckBox5.Checked then

FileAttrs := FileAttrs + faDirectory;
if CheckBox6.Checked then
FileAttrs := FileAttrs + faArchive;
if CheckBox7.Checked then

FileAttrs := FileAttrs + faAnyFile;

if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then

begin
with StringGrid1 do
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
Cells[1,RowCount-1] := sr.Name;
Cells[2,RowCount-1] := IntToStr(sr.Size);
end;
while FindNext(sr) = 0 do
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
RowCount := RowCount + 1;
Cells[1, RowCount-1] := sr.Name;

Cells[2, RowCount-1] := IntToStr(sr.Size);
end;
end;
FindClose(sr);
end;
end;
end;

----------------------------------------------
here you have the code and component you're talking about(TfindFile)

http://delphi.about.com/od/vclwritee.../tfindfile.htm

the part above is only how to locate the file on the remote computer.but you haven't said nothing about how you connect to that computer.

best regards,
Reputation Points: 14
Solved Threads: 16
Junior Poster
radu84 is offline Offline
171 posts
since Dec 2006
Jun 12th, 2007
0

Re: Verifying the existence of a file with a delphi program.

Thank you for your assistance, but I found a sort of kludgy way around the problem. I set a button to attempt to reopen the file, then to catch the error if the file doesn't exist and spit out a warning of my own if that happens, instead of the normal exception error. The 'Write file' button ends with a call to the test button.

As to linking into the remote location, I swiped some code from a program my predecessor wrote that does the job; it's simply opening up a specific Samba share on the remote (Linux) box. I'm still figuring out how it works, but I've got enough of it to do everything I needed for that.
Last edited by EnderX; Jun 12th, 2007 at 10:32 am.
Reputation Points: 483
Solved Threads: 1
Posting Shark
EnderX is offline Offline
999 posts
since Aug 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Program Serial Numbers
Next Thread in Pascal and Delphi Forum Timeline: html parser





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC