Solved

File search (shares)

Posted on 2002-03-28
3
298 Views
Last Modified: 2012-05-04
Hello,

I need some code on how to search for files on a share.

The share is \\Computername\c$
I also have to login to activate the share.

This is the code i use at this moment :

procedure GetFiles(DirStr: string; filelist: TList);
var DirInfo: TSearchRec;
   r : Integer;
   fr: PFile;
   pattern: String;
begin
 pattern := ExtractFileName(DirStr);
 if Pos('*', pattern) > 0 then
   DirStr := ExtractFilePath(DirStr)
 else
   pattern := '*.*';
 if DirStr[Length(DirStr)] <> '\' then
   DirStr := DirStr + '\';
 if SetCurrentDir((DirStr)) then
 begin
   r := FindFirst(pattern, FaAnyfile, DirInfo);
   while r = 0 do
   begin
     if (DirInfo.Attr and faDirectory) = 0 then
     begin
       New(fr);
       fr.filename := DirStr + DirInfo.Name;
       fr.filedate := FileDateToDateTime(DirInfo.Time);
       filelist.Add(fr);
     end;
     r := FindNext(DirInfo);
   end;
   FindClose(DirInfo);
   r := FindFirst('*.*', FaAnyfile, DirInfo);
   while r = 0 do
   begin
     if (DirInfo.Attr and faDirectory) <> 0 then
       if (DirInfo.Name <> '.') and (DirInfo.Name <> '..') then
// comment out the next line to exclude system directories
//          if (DirInfo.Attr and faSysFile) = 0 then
           GetFiles(DirStr + DirInfo.Name + '\' + pattern, filelist);
     r := FindNext(DirInfo);
   end;
   FindClose(DirInfo);
 end;
end;

0
Comment
Question by:Vincentg
3 Comments
 
LVL 9

Expert Comment

by:ginsonic
ID: 6904487
listening
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6905661
hi,
findfirst etc can search shared drives if you pass it \\computername\sharename\ but what system is it for?
(its different procedure to logon for different systems)

win9* use WNetVerifyPassword (mpr.dll)
winnt/2k use logonuser()

or if you can add the drive as a mapped drive you could do via WNetAddConnection
0
 
LVL 1

Expert Comment

by:drnadeem
ID: 6909734
listening
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
delphi custom sort exception 6 136
Why does formely good SQL code in Delphi 2009 not work under Windows 10? 5 87
Printing problem 2 81
RESTRequest Parameter 4 14
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

17 Experts available now in Live!

Get 1:1 Help Now