Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to retrieve full file-information from drive

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi!
Adir() gives me full detailled info about all files and dirs in a certain directory.
Is there a way to also include all subdirectories with filedetails??
basically like doscommand "Tree /F"
TIA
-Bart
 
Bart,

Yes. Pass "D" as the second parameter to ADIR(). This will give you the sub-directories within the target directory. Then call ADIR() again for each of the sub-directories.

The best way to do this is probably to write a recursive function.

Be aware that ADIR() will also return the two "special" sub-directories . and .. (that is, the current directory and its immediate parent). You will need to filter these out before doing a recursive call.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
You can use filer.dll that ships with VFP. It has problems if the start folder has a space in it but other than that it is easy to use it for the task you mention. It is also the DLL that VFP itself uses here:

do form home()+'tools\filer\filer.scx'

ie:
Code:
? GetTree(Home())
Select ;
  cast(filepath As Varchar(250)) As filepath, ;
  cast(filename As Varchar(250)) As filename, ;
  filesize, fattr, createtime, lastacc, lastwrite ;
  From filelist ;
  ORDER By 1,2


Function GetTree
  Lparameters tcStartDir

  Create Cursor filelist ;
    (filepath m, filename m, filesize i, ;
    fattr c(8), createtime T, lastacc T, lastwrite T)

  Create Cursor folderlist (filepath m)
  oFiler = Createobject('filer.fileutil')
  With oFiler
    .SearchPath = m.tcStartDir
    .Subfolder = 1
    .FileExpression = '*.*'
    .Find(0)
    For ix=1 To .Files.Count
      With .Files(ix)

        Insert Into filelist ;
          (filepath, filename, filesize, fattr, createtime, lastacc, lastwrite)  ;
          values ;
          (.Path, .Name, .Size, Attr2Char(.Attr), ;
          Num2Time2(.Datetime), Num2Time2(.LastAccessTime), Num2Time2(.LastWriteTime) )

      Endwith
    Endfor
    Return .Files.Count
  Endwith
Endfunc

Function Num2Time2
  Lparameters tnFloat
  Return Dtot(Date(1899,12,30) + m.tnFloat)
Endfunc

Function Attr2Char
  Lparameters tnAttr
  Return ;
    IIF(Bittest(tnAttr,0),'RO','RW')+;
    IIF(Bittest(tnAttr,1),'H','_')+;
    IIF(Bittest(tnAttr,2),'S','_')+;
    IIF(Bittest(tnAttr,4),'D','_')+;
    IIF(Bittest(tnAttr,5),'A','_')+;
    IIF(Bittest(tnAttr,6),'E','_')+;
    IIF(Bittest(tnAttr,7),'N','_')
Endfunc

Or you might use shell (warning-recursive code):
Code:
oShell=Createobject("shell.application")
GetFileList( HOME(),'FileList')

Select Cast(filePath As c(250)) From fileList

Procedure GetFileList(tcSourceFolder, tcCursorName)
  Local oFile
  If !Used(m.tcCursorName)
    Create Cursor (m.tcCursorName) (filePath m)
  Endif
  If Type('oShell.NameSpace(m.tcSourceFolder)') = 'O' ;
      And !Isnull(oShell.NameSpace(m.tcSourceFolder))
    For Each oFile In oShell.NameSpace(m.tcSourceFolder).items
      If !oFile.IsLink And oFile.IsFolder
        GetFileList(oFile.Path,m.tcCursorName)
      Else
        Insert Into (m.tcCursorName) Values (oFile.Path)
      Endif
    Endfor
  Endif
Endproc
and there are many other ways.

Cetin Basoz
MS Foxpro MVP, MCP
 
I need the information as I ame overthinking to create a personal intelligent BackUp application.
At home I plan to have a synology dual-HD NAS (in mirror-mode).
There are several PC's at home which I want to BU.
At first time all information from my data-drives will be backed-up to that NAS. I intend to create maps on the NAS having same name as the PC's which need to be backed up.
So far so good nothing special.
Than I want to use my own application which automaticly scans the pc's for modified files (archive bit set).
Taking the above into account I wonder if the approach of Cetin will work fine regarding the problem with space in map-name.
Mike's approach might be OK but it seems to be some more difficult to me to create the right recursive calls.

Alternative I could use Dos command dir /s > mapfile.txt.
I could more easily retrieve the files with full path from such an 'interface-file'.

Furthermore, as several PC's will be backed up on same drive I think that using the machines names will be helpfull.

Last to mention, as I want some intelligent BU, I don't like to overwrite old information on the NAS but rename the old BU-files to 'OriginalFilename.Ext_001' and after next BU 'originalfilename.ext_002'.

The reason why I want this : I sometimes made changes to program-code and after that I found that a version from weeks ago worked better. But than I didnot had that code available any longer.....

Well these are my thoughts. Any comments are welcome.

-Bart
 
Bart,

Why don't you simply use an off-the-shelf backup program? There are many utilities that will do exactly what you want, and many of them are free.

For example, you could look at SyncBack, from It seems to fit your requirements almost exactly.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike,
Indeed the link gives me a good opportunity.
Did you try that utility yourself already?
-Bart
 
As Mike has indicated, to accomplish file backups, there is most definitely no reason to 're-invent the wheel'.

There are many, many file backup applications out there and many of them are free or very low cost.

Do a Google search for backup free download and you will find many search 'finds'.

If you are planning on needing to backup files for a company with possibly multiple servers, etc. then you might need one of the more comprehensive packages, but if just for individual workstations, these free application work just fine.

The ones that I have been using are those in the "Simply" family at:

Good Luck,
JRB-Bldr
 
Bart,

Yes, I use the paid-for version of SyncBack every day. It has worked well for me for several years. There is also a free version, which has nearly all the same features as the paid version, but with a slightly less convenient user interface.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
If you buy a NAS or even only an external rady-to-use hdd drive like Western Digital MyBook series you typically get a backup utility anyway.

Windows comes with it's built in backup system and you may take a look at Windows Home Server to backup your personal computers of the whole family. I'd wait with WHS until the end of the year, though.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top