FileExists / FindFirst file path to long

Hi there,

When I use either of these they work fine, but if the file gets really long, like 120 characters they start to fail.... even though the file is actually there.

Help please!
LVL 10
wildzeroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike LittlewoodEngineerCommented:
What OS are you using?
pcsentinelCommented:
This might be tied up with the MAX_PATH constant which is declared as 260 if you need to get these you may have to implement a recursive directory listing which descneds through the directories to list the files

regards
wildzeroAuthor Commented:
This happens on windows XP
I tested it at 140 and it failed....
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

David_WardCommented:
Show us your code, that might help us help you.

wildzeroAuthor Commented:
ok

If FileExists(sFile) = true then
  ShowMessage('File Exists')
else
  ShowMessage('File not found');

sFile is string var set to
C:\Folder\Folder2\Follllllldddddddeeeeer\Fooooooolllddddddeeerr\Foooooooooolllllllddddddddddeeeeer\Foooooooollllldddddeeeeeeeeeeerrrr\img.jpg

And the path fails, even thou it actually exists (yes I have double checked)


carcotasuCommented:
try to use AnsiString var.
illusion_chaserCommented:
On Windows 2000 your sample code (and file path) work fine.
ic
wildzeroAuthor Commented:
illusion, will check it out on my copy of windows 2000 :-)

Thanks
AmigoJackCommented:
following should also work on nonNT (but it requires a filesystem which supports short filenames, like FAT32):


function FileExists(Filename: String): boolean;
var
  p1: pchar;
  s1, s2, s3: string;
begin
  result:= false;

  s1:= Filename;
  s2:= '';
  getmem(p1, 500);

  repeat
    s3:= copy(s1, 1, pos('\', s1));
    delete(s1, 1, length(s3));
    if getshortpathname(pchar(s2+ s3), p1, 500)= 0 then exit;
    s2:= strpas(p1);
  until pos('\', s1)= 0;

  if getshortpathname(pchar(s2+ s1), p1, 500)= 0 then exit;
  s2:= strpas(p1);

  freemem(p1);
  result:= true;
end;

David_WardCommented:
Your code works as expected on my XP box.


This leads to 2 silly questions;

Is there -any- chance that you have access permission issues?

What are your typical compilation switch values, particularly for "extended syntax" and "huge strings"?

AmigoJackCommented:
wildzero, have you found time to check my code?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.