# For Loop files with space - DOS Batch



## Kalaiselvigd (Oct 16, 2007)

In DOS batch script,

I am using for loop to read the content of the file. If the file name with *space *i am getting error. If i use file name with *""*, its taking file name as string  . How to over come this problem. Can any one you slove it.


----------



## JohnWill (Oct 19, 2002)

Actually, the proper way to specify a file name with a space is to surround the entire name and path with "", i.e. the path and file name of the HOSTS file. It's always worked in batch files for me.

"c:\Windows\system32\drivers\etc\HOSTS."


----------



## Kalaiselvigd (Oct 16, 2007)

Hi JohnWill,
Yep!!!. For specifying a file path within a "" is good pratice. But if i specify like that it is taking whole file path as string.


----------



## JohnWill (Oct 19, 2002)

I guess I'm not exactly sure what you are trying to do here. Are you reading file names out of a text file?


----------



## Kalaiselvigd (Oct 16, 2007)

I want to read file content in a temp file(its path or file name with space).

I got solution for this problem 
*for .......... ('Type "c:\fld name\file name.txt"') do ........*
If u give like this then you can get the file content.

Thanks.


----------



## obidon (Aug 12, 2007)

To specify a space in a filename, you can use the encoded representation "%20" without the quotes. This would concatenated the file name in place of the space. For example "file name.txt" could be "file%20name.txt".


----------

