# List of file names

**URL:** <https://boards.straightdope.com/t/list-of-file-names/343386>\
**Category:** Factual Questions\
**Created:** [February 7, 2006, 2:40pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386 "2006-02-07T14:40:38Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![grimpixie](https://avatars.discourse-cdn.com/v4/letter/g/ecb155/32.png) [@grimpixie](https://boards.straightdope.com/u/grimpixie)\
**Post date:** [February 7, 2006, 2:40pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/1 "2006-02-07T14:40:38Z")

</div>

I want to get a list of all the files (file paths to be precise) in a particular folder and all it’s sub-folders in a format that I can import into an Access database. How can I go about doing that?

Thanks  
Grim

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [February 7, 2006, 2:47pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/2 "2006-02-07T14:47:09Z")

</div>

It would be nice to know what OS you’re on. If you’re on Windows 2000 or later (and probably earlier versions too), you can type dir /s \> output.txt to a command prompt to get a file listing. You’ll have to do some cleaning.

---

<div class="post-metadata">

**Author:** ![grimpixie](https://avatars.discourse-cdn.com/v4/letter/g/ecb155/32.png) [@grimpixie](https://boards.straightdope.com/u/grimpixie)\
**Post date:** [February 7, 2006, 2:47pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/3 "2006-02-07T14:47:24Z")

</div>

I want to get a list of all the files (file paths to be precise) in a particular folder and all it’s sub-folders in a format that I can import into an Access database. How can I go about doing that?

Thanks  
Grim

---

<div class="post-metadata">

**Author:** ![grimpixie](https://avatars.discourse-cdn.com/v4/letter/g/ecb155/32.png) [@grimpixie](https://boards.straightdope.com/u/grimpixie)\
**Post date:** [February 7, 2006, 2:49pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/4 "2006-02-07T14:49:00Z")

</div>

Windows XP - I’ll give that a try.

Grim

---

<div class="post-metadata">

**Author:** ![grimpixie](https://avatars.discourse-cdn.com/v4/letter/g/ecb155/32.png) [@grimpixie](https://boards.straightdope.com/u/grimpixie)\
**Post date:** [February 7, 2006, 2:52pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/5 "2006-02-07T14:52:26Z")

</div>

> [@ultrafilter](#):
>
> You’ll have to do some cleaning.

No Jokes!! Thanks - that gets me the raw data…

Grim

---

<div class="post-metadata">

**Author:** ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://boards.straightdope.com/u/chrisk)\
**Post date:** [February 7, 2006, 2:59pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/6 "2006-02-07T14:59:35Z")

</div>

> [@grimpixie](#):
>
> No Jokes!! Thanks - that gets me the raw data…
> 
> Grim

Late chiming in I know, but “dir /s /b \>\whatever.txt” might be easier to work with.

---

<div class="post-metadata">

**Author:** ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)\
**Post date:** [February 7, 2006, 3:02pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/7 "2006-02-07T15:02:03Z")

</div>

Or you could install a third-party utility such as [DirPrint](http://www.softpile.com/Utilities/File_Management/Review_02373_index.html)

---

<div class="post-metadata">

**Author:** ![grimpixie](https://avatars.discourse-cdn.com/v4/letter/g/ecb155/32.png) [@grimpixie](https://boards.straightdope.com/u/grimpixie)\
**Post date:** [February 7, 2006, 3:16pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/8 "2006-02-07T15:16:46Z")

</div>

> [@chrisk](#):
>
> Late chiming in I know, but “dir /s /b \>\whatever.txt” might be easier to work with.

Thanks - but judicious use of Find and Replace and then importing as a fixed-length text file did the job without too much hassle. The file name proved to be sufficient, although yours actually gave me what I aksed for 🙂 .

---

<div class="post-metadata">

**Author:** ![Thudlow\_Boink](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/thudlow_boink/32/320_2.png) [@Thudlow\_Boink](https://boards.straightdope.com/u/Thudlow_Boink)\
**Post date:** [February 7, 2006, 3:37pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/9 "2006-02-07T15:37:24Z")

</div>

Heh. Every once in a while, knowing good old DOS comes in handy for something. 🙂

---

<div class="post-metadata">

**Author:** ![NinetyWt](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@NinetyWt](https://boards.straightdope.com/u/NinetyWt)\
**Post date:** [February 7, 2006, 4:40pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/10 "2006-02-07T16:40:35Z")

</div>

You can do it in DOS. Open the command (DOS) window in the directory of concern. Say you want to make a text file which is a list of the files in the directory. For the sake of illustration we will call it GrimFiles.txt

type DIR \> GRIMFILES.TXT

the resulting is a text file which you can import into Windows programs.

---

<div class="post-metadata">

**Author:** ![DarrenS](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@DarrenS](https://boards.straightdope.com/u/DarrenS)\
**Post date:** [February 7, 2006, 5:01pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/11 "2006-02-07T17:01:51Z")

</div>

You might prefer

DIR /S /B

This will give you the output in “bare” format, one filename per line. It will also recurse into subfolders as you requested. (the “/S” option)

---

<div class="post-metadata">

**Author:** ![Jpeg\_Jones](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@Jpeg\_Jones](https://boards.straightdope.com/u/Jpeg_Jones)\
**Post date:** [February 7, 2006, 6:12pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/12 "2006-02-07T18:12:03Z")

</div>

Also works if you tack a “.xls” on the end, to an Excel file.

dir /s /b \>filelist.xls

---

<div class="post-metadata">

**Author:** ![UncleBeer](https://avatars.discourse-cdn.com/v4/letter/u/977dab/32.png) [@UncleBeer](https://boards.straightdope.com/u/UncleBeer)\
**Post date:** [February 7, 2006, 7:24pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/13 "2006-02-07T19:24:15Z")

</div>

If you use dir /s /b \> filelist.txt, you get a either a brand new file, or you’ll overwrite an existing file of that name. If you use dir /s /b \>\> filelist.txt, you get either a brand new file, or you’ll append the results to an existing file.

And you can filter the search parameters through use of various wildcards. You can also sort your output just about any way you want. Enter the command dir /? for help with this.

---

<div class="post-metadata">

**Author:** ![Gary\_Robson](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/gary_robson/32/3448_2.png) [@Gary\_Robson](https://boards.straightdope.com/u/Gary_Robson)\
**Post date:** [February 7, 2006, 9:59pm UTC](https://boards.straightdope.com/t/list-of-file-names/343386/14 "2006-02-07T21:59:07Z")

</div>

> [@grimpixie](#):
>
> I want to get a list of all the files (file paths to be precise) in a particular folder and all it’s sub-folders in a format that I can import into an Access database.

It might help to know what operating system you’re running. On Unix or Mac OSX systems, the command would be:

ls -R1

---

<div class="post-metadata">

**Author:** ![K364](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/k364/32/5_2.png) [@K364](https://boards.straightdope.com/u/K364)\
**Post date:** [February 8, 2006, 1:19am UTC](https://boards.straightdope.com/t/list-of-file-names/343386/15 "2006-02-08T01:19:30Z")

</div>

You can use the following sub as a starting point:

```auto

Public Sub FolderDir()
'stores the file names from FOLDER into
'the table TABLENAME, in the field FIELDNAME
Const FOLDER = "C:	emp\" 'seems to need trailing backslash
Const TABLENAME = "Table1"
Const FIELDNAME = "FileName"
Dim sFolderName As String, sFileName As String
Dim db As Database, rs As Recordset
sFileName = Dir(FOLDER)
If sFileName = "" Then
    MsgBox "Invalid Folder!"
Else
    Set db = CurrentDb
    Set rs = db.OpenRecordset(TABLENAME)
    Do Until sFileName = ""
        rs.AddNew
        rs(FIELDNAME) = sFileName
        rs.Update
        sFileName = Dir()
    Loop
    rs.Close
    Set rs = Nothing
    Set db = Nothing
End If
            
End Sub

```

---

<div class="post-metadata">

**Author:** ![xash](https://avatars.discourse-cdn.com/v4/letter/x/c6cbf5/32.png) [@xash](https://boards.straightdope.com/u/xash)\
**Post date:** [February 8, 2006, 4:51am UTC](https://boards.straightdope.com/t/list-of-file-names/343386/16 "2006-02-08T04:51:37Z")

</div>

Merged two threads.

- **xash**  
General Questions Moderator
