batch-fileChanging Directories and Listing their Contents


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