Solved

EXTRACT FILE NAMES FROM A DIRECTORY TO A USABLE TEXT BASED LIST

Posted on 2013-06-20
4
572 Views
Last Modified: 2013-06-26
I tried to do a search and found nothing useful.   Our customer sent us a DVD with 5 main directory folders.  Each of these 5 folders contains hundreds of subfolders.  And each subfolder contains from 1 to as many as 10 part drawing in a standard PDF format.  What I'd like to do is extract all the file names in these folders and subfolders and create a list which I can eventually manipulate in Excel to determine if we have ever made this part before.  I think I can manage the back half of this little project, if I could just get a little help with creating the text list.

My network is based on WinServer 2003 w/AD.  Workstations use XP Pro.  I have the most experience using Excel with macros to get where I'm going.  



Thanks in advance,

Bryan
0
Comment
Question by:SPINAL-FUSION
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 39264117
You have several ways how to create a list of all files:

1) Start DOS mode (cmd.EXE) and execute following commands:

CD F:
DIR *.* /s > YourOutputFile.txt

F: is your CD-ROM, the "YourOutputFile.txt" is fully qualified file name incl. path. DIR command has additional parameters allowing to format the output slightly.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 39264230
You are asking in FoxPro zone so the following code will list the directory incl. subfolders. VFP 9 and a lot of memory is required to process large number of files:
CREATE TABLE dirlist (filename C(100))  && The column width should be greater than the longest file path on the DVD

LOCAL lcRootFolder, lcFileSkeleton
lcRootFolder = "F:"      && DVD drive
lcFileSkeleton = "*.*"

DO CreateDirList WITH ADDBS(m.lcRootFolder) + m.lcFileSkeleton

SELECT dirlist
COPY TO dirlist.txt TYPE DELIMITED

WAIT WINDOW "Done" NOWAIT


PROCEDURE CreateDirList
LPARAMETERS lcFileMask

WAIT WINDOW "Processing " + m.lcFileMask NOWAIT

LOCAL laDirs[1], laFiles[1], lnDirCnt, lnFileCnt, lnI

lnFileCnt = ADIR(laFiles, m.lcFileMask)
FOR lnI = 1 TO m.lnFileCnt
  INSERT INTO dirlist VALUES (ADDBS(JUSTPATH(m.lcFileMask)) + laFiles[m.lnI, 1])
NEXT

lnDirCnt = ADIR(laDirs, ADDBS(JUSTPATH(m.lcFileMask)) + "*.*", "D")
FOR lnI = 1 TO m.lnDirCnt
  IF !INLIST(laDirs[m.lnI, 1], '.','..')
    DO CreateDirList WITH ADDBS(JUSTPATH(m.lcFileMask)) + laDirs[m.lnI, 1] + '\' + JUSTFNAME(m.lcFileMask)
  ENDIF
NEXT

NOTE:  This character \  is backslash not the Korean Won currency symbol!

RETURN

Open in new window

ADIR function has additional parameters so you may decide what will be listed and what format of the filenames are on output.

The text output can be processed in Excel. You may decide about the different output format. See COPY TO command in VFP help.

You may test the code on some subfolder of your harddrive first.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 39267197
You can also do this as an Excel VBA Makro:

Dim row As Integer

Sub Start()
   GetDriveFiles "F:\"
End Sub

Sub GetDriveFiles(drive As String)
   Set o = CreateObject("Scripting.FileSystemObject")
   Set oFolder = o.GetFolder(drive)
   row = 1
   RecurseFolder oFolder
End Sub

Sub RecurseFolder(ByVal oFolder As Object)
    For Each oFile In oFolder.Files
       ActiveWorkbook.ActiveSheet.Cells(row, 1).Value = oFolder.Path + "\" + oFile.Name
       row = row + 1
    Next
   
    For Each oSubfolder In oFolder.SubFolders
       RecurseFolder oSubfolder
    Next
End Sub

Open in new window


Bye, Olaf.
0
 

Author Closing Comment

by:SPINAL-FUSION
ID: 39279034
Did exactly what I asked for.  Sorry it took 3 days to test.  I have been missing from the office due to health reasons.  Thanks for the replies.  And I may have posed in the wrong area as the VB base reply was more complicated than I needed.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question