get a directory listing, store it in worksheet

jdavis9

Active Member
Joined
Mar 8, 2002
Messages
337
Ok, here is what I need to do.
Get a directory listing of files located in c:\valvecurves\histdata\
all files as *.xls

list them in a worksheet, named "history_files"

What I currently do:

Using VB:
Shell and run a bat file which takes a directory listing
and writes it to a text file name dirlst.txt

the bat file look like this
dir *.xls /on /o-d >c:\valvecurves\histdata\dirlst.txt

then I open the text file, copy column "F" and paste it into my worksheet.

My question:
Isn't there an easier way to do this?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Here's a very simple VB example using the DIR function.

Code:
Sub DirectoryList()

Dim p As String
Dim f As String
Dim c As Long

p = "C:\ProgramFiles\Files\*.xls"
f = Dir(p)

c = 1

Do While f <> ""

    ThisWorkbook.Sheets(1).Cells(c, 6) = f

    c = c + 1
    f = Dir

Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,701
Messages
6,161,381
Members
451,700
Latest member
Eccymarge

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top