3

How to print file names with and without extensions in a Windows batch script. W...

 1 year ago
source link: https://gist.github.com/ScribbleGhost/c2dd2ee618870f2acad6a5e2a76c7e77
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
How to print file names with and without extensions in a Windows batch script. With relative or full path.

Getting file names in a batch script

Remember:

  • Replace double precentages with single precentage if you want to use it in CMD directly.
  • When file names are printed out, they already include double quotes.
@echo off

echo - - - Print the file names of all files in folder (with extension - relative path)
for %%A IN (*) DO (echo "%%~nxA")

echo. & echo.

echo - - - Print the file names of all files in folder (without extension - relative path)
for %%A IN (*) DO (echo "%%~nA")

echo. & echo.

echo - - - Print the file names of all files in folder (with extension - absolute path)
for %%A IN (*) DO (echo "%%~dpnxA")

echo. & echo.

echo - - - Print the file names of all files in folder (without extension - absolute path)
for %%A IN (*) DO (echo "%%~dpnA")

Example result:

- - - Print the file names of all files in folder (with extension - relative path)
"A beautiful picture.png"
"A movie file.mkv"
"An archive file.zip"
"Some text file.txt"
"test2.bat"


- - - Print the file names of all files in folder (without extension - relative path)
"A beautiful picture"
"A movie file"
"An archive file"
"Some text file"
"test2"


- - - Print the file names of all files in folder (with extension - absolute path)
"C:\example\A beautiful picture.png"
"C:\example\A movie file.mkv"
"C:\example\An archive file.zip"
"C:\example\Some text file.txt"
"C:\example\test2.bat"


- - - Print the file names of all files in folder (without extension - absolute path)
"C:\example\A beautiful picture"
"C:\example\A movie file"
"C:\example\An archive file"
"C:\example\Some text file"
"C:\example\test2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK