0

I want to Get a filename with a specific extension from a directory. Then in a result, I want to get rid of the extension name.

enter code here
@echo off
for %%f in (*.pdf) do (
   if "%%~xf"==".pdf" echo %%f
)

Let say in the directory the pdf files are (one.pdf, two.pdf, and three.pdf)

In the command above the results are

  • one.pdf
  • two.pdf
  • three.pdf

my preferred results are:

  • one
  • two
  • three

Thanks in Advance Ryl

  • I found this answer https://stackoverflow.com/questions/3215501/batch-remove-file-extension Regards, Ryl – Ryl Lunar Mar 10 '21 at 10:13

1 Answers1

0

You can use the cut command to remove the '.pdf'. For example, this will print out 'one':

echo 'one.pdf' | cut -d'.' -f 1
  • NB: This uses '.' as a delimiter and returns the part before the first '.'. So if you have multiple periods in your filename you'll need a different solution – Daniel Robinson Mar 10 '21 at 09:34
  • Thanks Daniel for your prompt reply. I found code that I'm looking for https://stackoverflow.com/questions/3215501/batch-remove-file-extension - Thanks Again – Ryl Lunar Mar 10 '21 at 10:14