-1

I have a script in batch that finds a filename from path. However, I dont't need the entire filename, only the first six characters. I thought that the following script would work, but it seems to not work with filenames.

set PL=%%~nG
set PL=%PL:~0,6%

It returns "~0,6".

npocmaka
  • 55,367
  • 18
  • 148
  • 187

1 Answers1

3

As you confirmed that this SET is inside for loop you'll need delayed expansion

setlocal enableDelayedExpansion

for %%G in (something) do (
  set PL=%%~nG
  set PL=!PL:~0,6!
  echo !PL!
)
npocmaka
  • 55,367
  • 18
  • 148
  • 187