batch-file Changing Directories and Listing their Contents

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • echo %cd% - displays the current path of the directory

  • cd "C:\path\to\some\directory" -changes the path of the directory

  • cd "%variable_containing_directory_path%" - also changes the path of the directory

  • cd /d E: - change to E: drive from a different drive

  • cd/ - changes directory back to current drive

  • echo %__CD__% - displays the current path of the directory with trailing backslash (undocumented)

  • echo %=C:% - The current directory of the C: drive (undocumented)

  • echo %=D:% - The current directory of the D: drive if drive D: has been accessed in the current CMD session (undocumented)

Remarks

Why is it important and what are they uses and advantages:

  • to open file or application in a directory using batch
  • to create andwrite and read files in a directory using batch
  • to know and list out all folders
  • to know where your batch file is running


Got any batch-file Question?