Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A Fox command dos's DIR MYFILE.TXT >FILELIST.TXT /S
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00043406
Message ID:
00044087
Vues:
40
For good, for bad or for ugly, here it is. . .

I had to change it for a few reasons. First, I was after the file names and subs which met the criteria. Second, ADIR will yield files, even if you use the "D" attribute. (The D means INCLUDE directories.) So I had to do a little weeding. However, I NEVER would have gone this route if I hadn't seen your code, and it works quite well. I've incorporated it into my client's code. I'll know more when it hits beta, but I'm sure we'll continue to use it.

Thanks, Paul!

JR

declare laFiles(1)
laFiles = ""

* Start at the root after saving the current directory
mOrigDir = SYS(5) +SYS(2003)
CHDIR \
m.lnFound = FindFiles("laFiles","XFER*.DBF","C:\")

wait window "Found "+alltrim(str(m.lnFound))+" files matching XFER*.DBF"

procedure FindFiles
LParameter lcArray, lcFileSpec, lcDirectory


* Validate the parameters
if type("m.lcDirectory") # "C"
m.lcDirectory = ""
endif
if (not empty(m.lcDirectory)) and ;
right(m.lcDirectory,1) # ":" and ;
right(m.lcDirectory,1) # "\"
m.lcDirectory = m.lcDirectory + "\"
endif
if type("m.lcFileSpec") # "C" or ;
empty(m.lcFileSpec)
m.lcFileSpec = ""
endif
if type("m.lcArray") # "C" or ;
empty(m.lcArray) or ;
type(m.lcArray+"(1,1)") # "C"
return
endif
* Add the current directory
private lnFound, laThisDir, lcFile
* Search the SubDirectories
m.lnFound = adir(laThisDir, m.lcDirectory+"*.*","D")
IF m.lnFound >0
ACOPY(LATHISDIR,LAALLDIR)
mLen =m.lnFound
FOR mLine =1 TO m.lnFound
* "IF TYPE(laAllDir(mLine,1)) = [C]" Returns an error
* when it gets to the deleted lines.
* This is a work-around only, and I'd like to do this more cleanly:
IF TYPE([laAllDir(mLine,1) = .F.]) =[U]
IF ! ([D] $ laAllDir(mLine,5))
ADEL(laAllDir, mLine)
* Set mLine & mLen back one to accommodate for deletion
mLine =mLine -1
mLen =mLen -1
ELSE
laAllDir(mLine,1) =LEFT(mOrigDir,3) +RTRIM(laAllDir(mLine,1))
ENDIF
ELSE
EXIT
ENDIF
ENDFOR
m.lnFound =mLine -1
DIMENSION laAllDir(m.lnFound,5)
mFileLine =0
mLine =1
DO WHILE .T. && would have used FOR m.lnFound, but it's dynamic, so am relying on an Exit command
mSubDir =RTRIM(laAllDir(mLine,1))
CHDIR (mSubDir)
* laFile will be the array with the subdir (1) and the filename (2)
m.lnFile = adir(laFile,lcFileSpec)
IF m.lnFile >0
FOR mFileLineTemp =1 TO m.lnFile
mFileLine =mFileLine+1
DIMENSION laFileDir(mFileLine,2)
laFileDir(mFileLine,1) =mSubDir
laFileDir(mFileLine,2) =laFile(mFileLineTemp,1)
ENDFOR
ENDIF
m.lnSubFound= adir(laThisDir, "*.*","D")
* m.lnFound now includes all D's and non-D's
FOR mFoundLine =1 TO m.lnSubFound
* Inserts only if it's a Directory and is not . or ..
IF ([D] $ laThisDir(mFoundLine,5) AND LEFT(laThisDir(mFoundLine,1),1) <>[.])
DIMENSION laAllDir(m.lnFound +1,5)
AINS(laAllDir, m.lnFound +1)
m.lnFound =m.lnFound +1
laAllDir(m.lnFound, 1) =mSubDir +[\] +laThisDir(mFoundLine, 1)
ENDIF
ENDFOR
mLine =mLine +1
IF mLine >ALEN(laAllDir,1)
EXIT
ENDIF
ENDDO
ENDIF

* Add Possible xfer* in the root:
mSubDir =[\]
CHDIR (mSubDir)
m.lnFile = adir(laFile,lcFileSpec)
IF m.lnFile >0
FOR mFileLineTemp =1 TO m.lnFile
mFileLine =mFileLine+1
DIMENSION laFileDir(mFileLine,2)
laFileDir(mFileLine,1) =mSubDir
laFileDir(mFileLine,2) =laFile(mFileLineTemp,1)
ENDFOR
ENDIF

* reset to the original directory
CHDIR (mOrigDir)

* Return the results
if empty(laFileDir(1,1))
return 0
else
return alen(laFileDir,1)
endif
CLARC Services, Inc.
3500 Tamiami Trail
Port Charlotte, FL 33952
www.clarc.com
(941) 743-0108
(800) 246-5488
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform