Link to home
Start Free TrialLog in
Avatar of Kann
Kann

asked on

Enumerate files and folders in NTFS

How to enumerate files and folders in Windows XP (NTFS) on a very low level (no FindFirst or NTQueryFile). Perhaps the Win32API DeviceIoControl function with a FSCTL_ const?
Thanks for your hints & help!
Kann
Avatar of shaneholmes
shaneholmes

Is this OK? ;)

procedure FindFilesAndDirs(Directory : string; var DestList : TStringList);
var
  sr : TSearchRec;
  dirs : array of string;
  n : integer;
  s : string;
begin
Directory := StringReplace(Directory,'/','\',[rfReplaceAll]);
if Directory[length(Directory)] = '\' then SetLength(Directory, length(Directory) - 1);
SetLength(dirs, 1);
dirs[0] := Directory;
while Length(dirs) > 0 do begin
  if FindFirst(format('%s\*.*',[dirs[0]]),faAnyFile,sr) = 0 then while FindNext(sr) = 0 do begin
    s := format('%s\%s',[dirs[0], sr.Name]);
    if FileExists(s) then begin
      DestList.Add(s);
    end else if sr.Name <> '..' then begin
      SetLength(dirs,length(dirs)+1);
      dirs[high(dirs)] := s;
    end;
  end;
  for n := low(dirs) to high(dirs) - 1 do dirs[n] := dirs[n+1];
  SetLength(dirs,length(dirs) - 1);
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  list : TStringList;
begin
list := TStringList.Create;
FindFilesAndDirs('C:\SomeDir',list);
ListBox1.Items := list;
list.Free;
end;
I believe he stated "no FindFirst"

<smile>

Shane
ou.. Didn't see that 'no' ;) sorry..
Avatar of Kann

ASKER

shaneholmes, this source (VWIN32) can only be used with Win9x. I need information about NTFS (Windows XP). Any hints?
Avatar of Kann

ASKER

I found a solution, but there is no source code or documentation available :-(
"NtFsControlFile : FSCTL_READ_MFT_RECORD makes it possible to very efficiently determine what files are on a NTFS volume and where their clusters are located, but its use requires detailed knowledge of undocumented NTFS on-disk data structures, "

I think, this question is to difficult to find a solution...
Avatar of Kann

ASKER

If you have an answer you get also 500 points here (together 1000 points)
https://www.experts-exchange.com/questions/20946139/1000-Points-Enumerate-files-and-folders-in-NTFS.html
if u want low level, use assembly.  Here is the link.  It uses interrupts to get the files.  Is this what you want?


http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH13/CH13-6.html#HEADING6-176
Avatar of Kann

ASKER

Hi fawndull, low level applied to NTFS programming technics, not to the programming language ;-) (The link descripted an articel about MSDOS, Sep. 1996.)
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial