0

From a visual foxpro 9 application we use the filer.fileutils activeX object to retrieve a list of all files in a folder.

This worked fine for several years. But now we only get some of the files from the folder, when we run it on the server with windows 2008. (Folder is a network location) When we run the very same code from a windows 7 workstation, we see all files

On the server we receive only .doc and .xls file, .docx and .xlsx files are not returned...

We then did switch the code over to use the scripting.filesystemobject, but this also only returns the .doc and .xls file, and the .docs and .xls files are missing

fso=createobject("scripting.filesystemobject")
fld=fso.getfolder(lcFolderName)
for each fil in fld.files
   ?"Name Of File: ", fil.name
   ?"Size: ", fil.size
   ?"Date created:", fil.DateCreated
   ?"Last modified:", fil.DateLastModified
next

As this stopped working about 2-3 weeks ago, we are wondering what setting or security update did cause this on the server...

André Schild
  • 4,592
  • 5
  • 28
  • 42

2 Answers2

1

Tamar is right... and it's something that has been available for a long time. If you localize your parameter of the path to start and localize the variables you are working with for the array handling, you should be good. I personally never try to using SET DEFAULT TO or SET PATH TO. This method below just accepts a path and uses IT as the basis to walk the directory tree. I even put the results in a cursor for you to play with as you need. You could even add other columns if you wanted to add your own purposes. The only thing this does not have is the Date created... just the date modified.

CREATE CURSOR C_DirWalk ;
(   justThePath c(50),;
    TheFile     c(50),;
    TheSize     i,;
    TheDate     d,;
    TheTime     c(8),;
    TheFlags    c(5) )  

walkTheDir( "C:\SomeFolder\SomeSubFolder\" )


PROCEDURE WalkTheDir
    LPARAMETERS justOneDirectory

    */ Make sure it always has the trailing backslash
    justOneDirectory = ADDBS( ALLTRIM( justOneDirectory ))

    LOCAL ARRAY laOneDirPath[1,5]
    LOCAL lnF, lnI
    */ Include any Hidden or Directories...
    lnF = ADIR( laOneDirPath, justOneDirectory + "*.*", "HD" )
    FOR lnI = 1 TO lnF
        INSERT INTO C_DirWalk;
            ( justThePath,;
                TheFile,;
                TheSize,;
                TheDate,;
                TheTime,;
                TheFlags );
            values;
            (   justOneDirectory,;
                laOneDirPath[ lnI, 1],;
                laOneDirPath[ lnI, 2],;
                laOneDirPath[ lnI, 3],;
                laOneDirPath[ lnI, 4],;
                laOneDirPath[ lnI, 5] )


        */ If this was a directory, make a recursive call but tacking on
        */ this path... but do NOT process directories that are
        */ the "." (same directory) or ".." (parent)
        IF      "D" $ laOneDirPath[ lnI, 5] ;
            AND LEN( CHRTRAN( laOneDirPath[ lnI, 1], ".", "" )) > 0
            */ Yes, a valid path OTHER than just "." or ".."
            WalkTheDir( justOneDirectory + laOneDirPath[ lnI, 1] )
        ENDIF 
    ENDFOR 
ENDPROC 
DRapp
  • 47,638
  • 12
  • 72
  • 142
0

Why not use the built-in ADIR() function? It'll fill an array with a list of all files in a folder, or all those matchine a filespec.

Tamar E. Granor
  • 3,817
  • 1
  • 21
  • 29
  • The problem is, that I have to walk a whole tree. With ADIR() I have to always change the current directory with SET DEFAULT TO and then later on revert it back... – André Schild Jun 18 '13 at 08:06