Dos - Display relative file path of all files from the current directory

By xngo on June 23, 2019

You can call the script below and then filter what you want using find command as follows:

REM Display relative file path of all files from current directory.
REM   Then select file paths that contain ".doc"
CALL relative_file_path.bat | find /I ".doc"

relative_file_path.bat

@ECHO OFF
REM Display relative file path of all files from the current directory
SETLOCAL DisableDelayedExpansion
SET "r=%__CD__%"
FOR /R . %%F IN (*) DO (
  SET "p=%%F"
  SETLOCAL EnableDelayedExpansion
  ECHO(!p:%r%=!
  ENDLOCAL
)

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.