Jump to content
Ian Branch

FileExists(xxxxx) in a network?

Recommended Posts

Hi Team,

Using D10.3.

I am trying to use FileExists(xxx); in a network environment but it doesn't seem to like it.  I am using the following test code..

{code}

procedure TForm21.Button1Click(Sender: TObject);
var
  sAppName: string;
begin

  sAppName := 'Testfile.exe';
  sAppName := Copy(sAppName, 0, LastDelimiter('.', sAppName) - 1);
  sAppName := ExtractFilePath(Application.ExeName) + sAppName + '.Tips';
  MessageDlg('Tips file name is - '+sAppName, mtInformation, [mbOK], 0);
  //
  if FileExists(sAppName) then
     MessageDlg(sAppName+' found OK.', mtInformation, [mbOK], 0)
  else
     MessageDlg('Unable to find '+sAppName, mtInformation, [mbOK], 0);
  //
end;

{code}

The two MessageDlg show the correct information and it all works fine on my PC.

When I run it from the server on the network the MessageDlg still show the correct server drive/path and filename however it doesn't find 'the 'Testfile.Tips'.

Have I done something wrong?  Should I be using some other Test for existence of the file?

Note - The initial sAppName is normally derived from Application.ExeName but I have hard coded it for the test app.

 

Regards & TIA,

Ian

Edited by Ian Branch

Share this post


Link to post

For the record, I have tried hard coding..

{code}

  sAppName := '\\192.168.1.35\F-TestServer\C:\TestArea\Testfile.Tips';

  MessageDlg('Tips file name is - '+sAppName, mtInformation, [mbOK], 0);
  //
  if FileExists(sAppName) then

....

....

{code}

Without success.

Edited by Ian Branch
Added aditional piece of code.

Share this post


Link to post

Some very old versions of Delphi had this issue, simple fix was to use:

 

function MyFileExits(FileName: string): boolean;
var
  SearchRec: TSearchRec;
begin
  if (FindFirst(FileName, faAnyFile, SearchRec) = 0) then
  begin
    SysUtils.FindClose(SearchRec);
    Result := True;
  end
  else
    Result := False;
end;

 

Share this post


Link to post

Hi Fred,

Thanks for that but it didn't fix the issue.

I should have stated up front i was using D10.3.  My bad.

Ian

Share this post


Link to post

OK,

 

sAppName := '\\192.168.1.35\F-TestServer\C:\TestArea\Testfile.Tips'; 

 

should be

 

sAppName := '\\192.168.1.35\F-TestServer\C$\TestArea\Testfile.Tips'; 

 

Share this post


Link to post

The format is \\<server>\<share>\<path>

Admin shares can be accessed with <drive letter>$.

 

After taking a closer look at what you are doing, why would 'c:' be a valid path inside a share?

 

 

 

 

Share this post


Link to post

The bottom line here is I am trying to do something in an environment I am unfamiliar with.

I am working remotely into a Customer's test PC.

Looking closer at the environment I suspect that he has it locked down tightly.  I assumed F-TestServer was the root directory of the PC .  As there are several drives on it I assumed it needed a drive specifier.

All very confusing att, that is why I am trying to make sense of it.

Ian

Share this post


Link to post
49 minutes ago, Ian Branch said:

All very confusing

 

Try:

LTips := ChangeFileExt(Application.ExeName, '.Tips');

 

Share this post


Link to post

All,

Thank you for your inputs.  I had no joy making it work.

I have instead changed the mechanism to .ini file processing which is working fine.

Regards & Tks again.

Ian

Share this post


Link to post

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

×