| | |
Verifying the existence of a file with a delphi program.
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Aug 2006
Posts: 999
Reputation:
Solved Threads: 1
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.
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.
"No trees were harmed in the production of this post. However, several electrons were severely inconvenienced."
Kumquat.
Kumquat.
•
•
Join Date: Dec 2006
Posts: 171
Reputation:
Solved Threads: 16
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,
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,
•
•
Join Date: Aug 2006
Posts: 999
Reputation:
Solved Threads: 1
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.
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.
"No trees were harmed in the production of this post. However, several electrons were severely inconvenienced."
Kumquat.
Kumquat.
![]() |
Similar Threads
- Creating a delphi program to autoinstall other programs? (Pascal and Delphi)
- run program and rename file script help please (Shell Scripting)
- About;Blank Please Help, Hijack Log File (Viruses, Spyware and other Nasties)
- Error message when trying to open an external file in C++ program (C++)
- cannot delete file/file in use by other program (Windows NT / 2000 / XP)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Program Serial Numbers
- Next Thread: html parser
| Thread Tools | Search this Thread |
Tag cloud for Pascal and Delphi





