Solved

Searching for files in path longer than 255 characters

Posted on 2002-03-10
13
398 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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 33

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now