0
setlocal
set "s=DIR D:\MyFolder /S /Q ^|FIND /i "Owner" ^|FIND /v /i "sample" ^|findstr /m /i "\.mkv$""
for /f "Tokens=5,6*" %%a in ('%s%') do >>%tmp%\list.txt echo %%a %%b %%c
wscript "C:\my.vbs" 

Hey guys, I have this code. Getting mkv files owned by Owner from MyFolder. And shows them via VBS.

And these are my files.

The.Leftovers.S01E02.720p.BLABLABLA
Falling.Skies.S04E03.720p.BLABLABLA

I want to limit the length to 20 letters. Or remove before the 720p

The.Leftovers.S01E02
Falling.Skies.S04E03

I read some guides but I couldn't import them into for /f "Tokens. Is it possible to do that? If so how?

Rıdvan Çetin
  • 183
  • 5
  • 16
  • Please show some (say about 6) sample lines exectly as they are produced by `'%s%'`. It would be next to impossible to anticipate the precise structures you would be using. Please make sure the samples you extract come from different directories and some of the names contain spaces, if that is the case. – Magoo Jul 14 '14 at 01:38

1 Answers1

0

Here is a batch file which will list the contents of the current directory, trimming all the names to 20 characters.

SETLOCAL ENABLEDELAYEDEXPANSION
@echo off

for %%f in (*) do (
    set TMPF=%%f
    echo !TMPF:~0,20!

)

For more help, run SET /? for help about the ~0,20 syntax and examples, and CMD /? for what the ENABLEDELAYEDEXPANSION does and what the !! does.

I can't for sure say how this would fit in your code, but maybe something like:

SETLOCAL ENABLEDELAYEDEXPANSION
for /f "Tokens=5,6*" %%a in ('%s%') do (
    set TMPA=%%a
    >>%tmp%\list.txt echo !TMPA:~0,20! %%b %%c
)
TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87