-
Both
MDandMKDIRdo the same thing: create a new folder.MD foldername MKDIR foldername
MD Logs MD D:\Backups\2025\July
- If the full path doesn't exist, it creates all missing folders (like
mkdir -pin Unix). - No error if the folder already exists.
- If the full path doesn't exist, it creates all missing folders (like
-
Used to delete folders. If the folder is not empty, you must use the
/Sflag.RD foldername RD /S /Q foldername
Option Description /SRemove all subfolders and files /QQuiet mode (no prompt) RD EmptyFolder RD /S /Q Logs\OldReports
-
Shows the contents of a directory, like
lsin Unix.DIR [path] [/options]Option Description /BBare format (just names) /SInclude subdirectories /AFilter by attributes /OSort output /TWhich time field to use DIR DIR /B *.txt DIR /S /B *.log > loglist.txt DIR /O:-D :: Sort by date descending
-
Changes the working directory for the script.
CD folder CD .. CD /D drive:\path
Option Description /DChange drive and directory simultaneously CD D:\Projects CD /D C:\Scripts\Logs CD ..
SET CURDIR=%CD% ECHO You are in: %CURDIR%
-
These are often underused, but extremely useful when jumping around directories in a script.
PUSHD C:\Temp :: do something in Temp POPD
This is safer and cleaner than manually changing back using
CD.PUSHD D:\Backups\July :: Run copy or cleanup here PUSHD Logs :: Nested operation POPD POPD
-
MD MyApp CD MyApp MD Logs MD Config MD Temp
-
IF EXIST OldData ( RD /S /Q OldData )
-
DIR /S /B *.csv > csv_files.txt
-
PUSHD C:\Source COPY *.txt D:\Archive\ POPD
| Tip / Problem | Solution |
|---|---|
| Quoting paths with spaces | Always use double quotes "C:\My Folder\" |
CD doesn’t change drive |
Use CD /D or PUSHD |
| Folder already exists | MD won’t error — safe for repeat use |
| Want to preserve original location | Use PUSHD and POPD |
Output clutter from DIR |
Use /B or redirect to file |
| Command | Description |
|---|---|
MD |
Make a new directory |
RD |
Remove directory |
DIR |
List contents of a directory |
CD |
Change working directory |
PUSHD |
Change + remember current folder |
POPD |
Go back to remembered folder |