Ian Branch 127 Posted January 16, 2019 (edited) 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 January 16, 2019 by Ian Branch Share this post Link to post
Ian Branch 127 Posted January 16, 2019 (edited) 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 January 16, 2019 by Ian Branch Added aditional piece of code. Share this post Link to post
FredS 138 Posted January 16, 2019 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
Ian Branch 127 Posted January 16, 2019 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
FredS 138 Posted January 16, 2019 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
Ian Branch 127 Posted January 16, 2019 Hi Fred, Sorry to report no good. 😞 For my education, why the $ instead of :? Ian Share this post Link to post
FredS 138 Posted January 16, 2019 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
Attila Kovacs 629 Posted January 16, 2019 @Ian Branch Are you holding some infos back? How is a colon in your UNC path? Linux server? Does samba supports colon in UNC? Share this post Link to post
Ian Branch 127 Posted January 16, 2019 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
FredS 138 Posted January 16, 2019 49 minutes ago, Ian Branch said: All very confusing Try: LTips := ChangeFileExt(Application.ExeName, '.Tips'); Share this post Link to post
Ian Branch 127 Posted January 17, 2019 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