Solved

Searching for files in path longer than 255 characters

Posted on 2002-03-10
13
401 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to draw animated progressbar in Tvirtualstringtree 5 117
FMX enumerated colours 2 84
Delphi - replicating a form 8 66
Print Graphic and Text to Epson TM-T88v 12 185
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

20 Experts available now in Live!

Get 1:1 Help Now