Space in Batch File

I'm fairly new to batches. Starting to learn the basics but already run into a problem.

So my Code looks something like this:

findstr /i /m Findthisstring C:\Users\XY\Desktop\Start\*.* > test.lst
for /f %%I in (C:\Users\XY\Desktop\test.lst) do @move %%I C:\Users\XY\Desktop\Target\

pause

The Problem here is, that I also receive Files with spaces. For Example "File with Spacer.pdf". I already tried to use quotation marks. But these didnt work out for me.

Maybe you can give me a hint how to solve this one.

Thanks!

Edit:

Tried to use the quotation marks direct at the file name ("* ".*).

findstr /i /m Findthisstring C:\Users\XY\Desktop\Start\"*".* > test.lst
for /f %%I in (C:\Users\XY\Desktop\test.lst) do @move %%I C:\Users\XY\Desktop\Target\

pause

And I tried to use it for the whole path ("C:\Users\XY\Desktop\Start*.*")

findstr /i /m Findthisstring "C:\Users\XY\Desktop\Start\*.*" > test.lst
for /f %%I in (C:\Users\XY\Desktop\test.lst) do @move %%I C:\Users\XY\Desktop\Target\

pause

1 answer

  • answered 2020-06-03 05:44 TQL

    So i managed to get it working with the "DELIMS=" command. Also thanks @mark for the Hint with the Quoted "%%I".

    My final Code:

    findstr /i /m Findthisstring C:\Users\XY\Desktop\Start\"*".* > test.lst
    for /f "DELIMS=" %%I in (C:\Users\XY\Desktop\test.lst) do @move "%%I" C:\Users\XY\Desktop\Target\
    
    pause