How to Create List of File Names Using Batch File

list-file-names-using-batch-file-simplemsoffice

In this post, we will provide you with multiple batch script codes based on different criteria. We will provide you with the best and simple way to work with batch file script. If you don’t know, how to make a batch file then read How to create a Batch File? We will also provide you with simple steps here, so you can make batch files very easily even if you are a beginner.

Let’s Start…

Step 1: Open Notepad in your system.

Step 2: Copy the below code in Notepad:

1
dir > list.csv

Step 3: Save the Notepad file in any folder you want to make list for and give any name like “makelist.bat“.

Now you can run the batch file by double-clicking on it and it will make a list of files and folders with their properties like size, creation date, etc. This file will create a CSV file because we have given a .csv extension in the code. We can also give it a .txt extension.

Dir   – It collects all the files and folder details within a particular folder.
   – This symbol exports details to other applications with the new file names.
List  – This is the file name
.csv – This is the file name extension. We can also change from .txt to .csv if we want to see the result in an excel file.

list-file-names-using-batch-file-simplemsoffice1

Note:- If you want to edit a batch file, then right-click on it and then click on “Edit” or you can open the script in Notepad, and after editing you can save it.

Create a name list for all files and folders using a batch file
If you want only files/folders names then use the below code:

1
dir /b > list.csv

/b – It exports only the names of files/folders with their extension.

Create a batch file to list file names only
If you want only files name in the list, then use the below code:

1
dir /a-d /b > list.csv

/a-d – It exports only files name with their extension. No folder will be listed in this command

Create a batch file to list folder names only
If you want only files name in the list, then use the below code:

1
dir /a:d /b > list.csv

/a-d – It exports only files name with their extension. No folder will be listed in this command

Read: How to Run Multiple Batch Files?

Create a list of all files/folders and subfolders with their directory locations
If you want files/folders names with folder locations then use the below code:

1
dir /s /b > list.csv

/s – Add location with files and folders name. Also, list all files and folders from its subfolders.

1
dir /a-d /s /b > list.csv

/a-d – It exports only files name with their extension. No folder will be listed in this command.
You can use multiple parameters that fit your requirement.

Create a list of all files with selected extensions or file types
If you are looking to list all files for a particular type i.e. extension. Like if you want to list all excel files available in a folder then use the below code:

1
dir  /b *.xlsx > list.csv

*.xlsx – Just give the extension name, you want to create a list for. If you want to list only image files that have the extension .jpeg then define only *.jpeg and it will list all image files with that extension.


0 Comments

Leave a Comment

Your email address will not be published. Required fields are marked *