Batch Script – Functions - Listing Folder Contents - Batch Script

The listing of folder contents can be done with the dir command. This command allows you to see the available files and directories in the current directory. The dir command also shows the last modification date and time, as well as the file size.

Syntax

S.No. Options & Description
1. [drive:][path][filename]

Specifies drive, directory, or files to list

2. /A

Displays files with specified attributes.

3. attributes

D - DirectoriesR - Read-only files

H - Hidden filesA - Files ready for archiving

S - System filesI - Not content indexed files

L - Reparse Points- Prefix meaning not

4. /B

Uses bare format (no heading information or summary).

5. /C

Displays the thousand separator in file sizes. This is the default. Use /-C to disable the display of the separator.

6. /D

Same as wide but files are list sorted by column.

7. /L

Uses lowercase.

8. /N

New long list format where filenames are on the far right.

9. /O

Lists by files in sorted order.

10. sortorder

N By name (alphabetic), S By size (smallest first), E By extension (alphabetic), D By date/time (oldest first), G Group directories first - Prefix to reverse order

11. /P

Pauses after each screen is full of information.

12. /Q

Displays the owner of the file.

13. /R

Displays alternate data streams of the file.

14. /S

Displays files in the specified directory and all subdirectories.

15. /T

Controls what time field is displayed or used for sorting.

16. timefield

C - Creation

A - Last Access

W - Last Written

17. /W

Uses wide list format.

18. /X

This displays the short names generated for non-8dot3 file names. The format is that of /N with the short name inserted before the long name. If no short name is present, blanks are displayed in its place.

19. /4

Displays four-digit years.

Let’s see some of the examples on how to use the DIR command.

Examples

The above command lists any file that ends with the .exe file extension.

The above command uses multiple filespecs to list any files ending with .txt and .doc in one command.


Lists only the directories in the current directory. If you need to move into one of the directories listed use the cd command.


Lists the files in the directory that you are in and all sub directories after that directory. If you are at root "C:\>", type this command, this will list to you every file and directory on the C: drive of the computer.

If the directory has lots of files and you cannot read all the files as they scroll by, you can use the above command and it displays all files one page at a time.

If you don't need file information you can use the above command to list only the files and directories going horizontally, taking as little space as needed.


The above command will list all the files and directories in the current directory and the sub directories, in wide format and one page at a time.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Batch Script Topics