Solved

Searching for files in path longer than 255 characters

Posted on 2002-03-10
13
407 Views
Last Modified: 2010-05-18
Hi there,

I am looking for a FindFirst, FindNext equivalent to find files and directories even if the path is longer than 255 characters.

I was trying to use the FindFistFileW function and prefixing the path name with "\\?\", however, I always get error code 3.

I'll give 300 points for some working code, it's urgent.

In a nutshell: I need to be able to search for directories and files even if the path name is longer than 255 characters.


Thanks,
Oliver
0
Comment
Question by:novowi
13 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 6854688
It works fine for me with "\\?\C:\boot.ini" (I don't have such long pathes on my PC) - but only in NT based systems! I guess you're trying it in win9x? That is not supported there. If you need this stuff for win9x, then you will probably have to deal with IShellFolder and that stuff...   :-(

Regards, Madshi.
0
 

Author Comment

by:novowi
ID: 6854695
Thanks Madshi,

I am running it on NT4 and W2K, not W95/98.

Regards,
Oliver
0
 

Author Comment

by:novowi
ID: 6854700
Madshi,

Does your madSecurity etc. work with such long file and path names ?

Thanks,
Oliver
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:novowi
ID: 6854767
Madshi,

Does your madSecurity etc. work with such long file and path names ?

Thanks,
Oliver
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6854777
I've not tested it yet. Perhaps madShell can do that, madShell encapsulates the IShellFolder stuff. See here for documentation:

http://help.madshi.net/Data/madShell.htm

However, I think it should work with that \\?\. Can you show a short piece of your code?

Regards, Madshi.
0
 
LVL 20

Accepted Solution

by:
Madshi earned 300 total points
ID: 6854781
P.S: Does it work with your code, when you use that \\?\ on a short path, like e.g. '\\?\C:\*.*'?
0
 

Author Comment

by:novowi
ID: 6854788
Unfortunately not :(

Is there anything you can do about ?

Thanks,
Oliver
0
 

Author Comment

by:novowi
ID: 6854812
By the way, I solved the problem with the FindFirstFileW function. Used the wrong variable type.

However, two problems remain.
- Using madSecurity with such long dir/file names doesn't work.

- Using the FindFirstFileW function uses the wrong character set. I need to get the file names returned in OEM
and the SetFileAPIsToOEM function does not help. It works only if I use the normal FindFirst and Findnext functions.

Regards,
Oliver
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6854827
>> Using the FindFirstFileW function uses the wrong character set.

?  Converting from wide character to ansi is very easy. Something like this:

var w32fd : TWin32FindDataW;
    str   : string;
begin
  ...
  str := wideString(w32fd.cFileName);

That's it. Or do you mean something different? I'm not sure.

And where exactly is the problem with madSecurity? Which call exactly fails? Some code, please!

Regards, Madshi.
0
 

Author Comment

by:novowi
ID: 6854832
By the way, I solved the problem with the FindFirstFileW function. Used the wrong variable type.

However, two problems remain.
- Using madSecurity with such long dir/file names doesn't work.

- Using the FindFirstFileW function uses the wrong character set. I need to get the file names returned in OEM
and the SetFileAPIsToOEM function does not help. It works only if I use the normal FindFirst and Findnext functions.

Regards,
Oliver
0
 
LVL 17

Expert Comment

by:inthe
ID: 6854867
i was following q wondering why you wouldnt get it to work as
i just tried FindFirstFileW on a path of 673 length and it worked ok as it should.


>>get the file names returned in OEM
now sure what that means but it wouldnt be:

Win32FindData.cAlternateFileName

would it?
0
 
LVL 34

Expert Comment

by:Slick812
ID: 6855400
this may help, I've used it to bypass real long file paths in some API functions that only take MAX_PATH charaters, but I don't remember which OS it will work under, I think NT, Win9x


function ShortPathName(const LongName: string): string;
var
  Buffer: array[0..MAX_PATH - 1] of Char;
begin
  SetString(Result, Buffer,
    GetShortPathName(PChar(LongName), Buffer, SizeOf(Buffer)));
end;
0
 

Author Comment

by:novowi
ID: 6862836
Madshi,

I did some thourough checking and your questions and suggestions finally helped me to sort it all out. It's all working.

Thanks,
Oliver
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question