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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get all file information in a directory

Windows Scripting

How to get all file information in a directory

by  Mike Gagnon  Posted    (Edited  )
This requires a Windows Scripting version 5.6 or more.
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp

This code was adapted to VFP from a sample found in the Windows Scripting documentation.

Code:
oFolder = GETDIR()
GenerateAllFolderInformation(oFolder)
FUNCTION GenerateAllFolderInformation
   LPARAMETERS loFolder
   #DEFINE TABSTOP CHR(9)
   #DEFINE NewLine CHR(13)
   PUBLIC  lcText
   LOCAL lcSubFolders
   LOCAL lcSubFolder
   LOCAL lcFiles
   LOCAL lcFile
   FSO = CREATEOBJECT("Scripting.FileSystemObject")
   lcFolder = FSO.getfolder(loFolder)
   lcText = "Folder:" +TABSTOP+ lcFolder.PATH+ NewLine+ NewLine
   lcFiles = lcFolder.FILES
   IF lcFiles.COUNT =1
      lcText = "There is 1 file" & NewLine
   ELSE
      lcText = lcText+ "There are " +TRANSFORM(lcFiles.COUNT)+ " files" +NewLine
   ENDIF

   IF lcFiles.COUNT <> 0
      FOR EACH lFile IN lcFiles
         GenerateFileInformation(lFile)
      NEXT
   ENDIF
   STRTOFILE(lcText,"c:\fileinfo.txt")
   MODIFY FILE c:\fileinfo.txt
FUNCTION GenerateFileInformation
   LPARAMETERS lcFile
   lcText = lcText+NewLine + "Path:" + TABSTOP + lcFile.PATH
   lcText = lcText+NewLine + "Name:" + TABSTOP + lcFile.NAME
   lcText = lcText + NewLine + "Type:" + TABSTOP + lcFile.TYPE
   lcText = lcText + NewLine + "Attribs:" + TABSTOP + ShowFileAttr(lcFile)
   lcText = lcText + NewLine + "Created:" + TABSTOP + DTOC(lcFile.DateCreated)
   lcText = lcText + NewLine + "Accessed:" + TABSTOP + DTOC(lcFile.DateLastAccessed)
   lcText = lcText + NewLine + "Modified:" + TABSTOP + DTOC(lcFile.DateLastModified)
   lcText = lcText + NewLine + "Size" + TABSTOP + TRANSFORM(lcFile.SIZE) + NewLine
ENDFUNC
FUNCTION ShowFileAttr
   LPARAMETER llcFile
   ATTR = llcFile.ATTRIBUTES
   DO CASE
      CASE ATTR = 0
         ShowFileAttr = "Normal"
      CASE ATTR =1
         ShowFileAttr = "Read-Only"
      CASE ATTR  = 2
         ShowFileAttr = "Hidden"
      CASE ATTR  = 4
         ShowFileAttr = "System"
      CASE ATTR  = 8
         ShowFileAttr = "Volume"
      CASE ATTR  = 16
         ShowFileAttr = "Directory"
      CASE ATTR  = 32
         ShowFileAttr = "Archive"
      CASE ATTR = 64
         ShowFileAttr = "Alias"
      CASE ATTR = 128
         ShowFileAttr = "Compressed"
   ENDCASE
   RETURN ShowFileAttr
ENDFUNC

Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top