How to ignore filename spaces in FOR loop %%var?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

How to ignore filename spaces in FOR loop %%var?

#1 Post by tinfanide » 08 Jan 2012 00:02

In CMD:

Code: Select all

FOR /R "c:\" %F IN (*.txt) DO START %F


The codes are fine, yet it cannot open files with filename spaces
e.g. text file.txt

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: How to ignore filename spaces in FOR loop %%var?

#2 Post by !k » 08 Jan 2012 01:09

... DO START "" "%F"

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: How to ignore filename spaces in FOR loop %%var?

#3 Post by tinfanide » 08 Jan 2012 05:33

Thanks. It seems that after some testing "" is not a must.

Another example (posted by me earlier here)

Code: Select all

:: "%F" ignores filenames with spaces
FOR %F IN ("c:\*.txt) DO MOVE "%F" "d:\"

aGerman
Expert
Posts: 4740
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to ignore filename spaces in FOR loop %%var?

#4 Post by aGerman » 08 Jan 2012 08:30

Each command has its own syntax. See START /?. The first argument enclosed in quotation marks is interpreted as window title. Since that does not affect non-console applications you should use the empty string ("") instead.

Regards
aGerman

Raistlin73
Posts: 4
Joined: 23 Jan 2012 03:55

Re: How to ignore filename spaces in FOR loop %%var?

#5 Post by Raistlin73 » 23 Jan 2012 05:38

Hi If using a cmd file you could try using delims eg.

FOR /R "delims=" "c:\" %F IN (*.txt) DO START %F


I had issues pulling directory stings from a txt file containing spaces (script would drop without complete path when hitting a space) after using delims= it resolved the issue.

Post Reply