# Batch script to create files with special characters



## scambro (Mar 28, 2007)

Hello,

I have the following batch file that works great, until I happen to execute it on a file with a + in it. 

@echo off
cls
for /r %%f in (*txt) do copy %%f m:\text files

I searched around for a bit, but I couldn't get any of the information I found about escape characters to work. How can I make the batch file treat the file name in %%f as a literal? 

Thanks!


----------



## scambro (Mar 28, 2007)

Any ideas or pointers to set me in the right direction? Thanks!


----------



## html81993 (Jul 8, 2005)

scambro said:


> @echo off
> cls
> for /r %%f in (*txt) do copy %%f m:\text files


 The list (in parenthesees), at least posted here, needs the period. That might help a little bit.


----------



## Rollin_Again (Sep 4, 2003)

What exactly does this batch file do? Maybe you could accomplish the same thing with a VBS script?

Regards,
Rollin


----------



## html81993 (Jul 8, 2005)

Rollin_Again said:


> What exactly does this batch file do? Maybe you could accomplish the same thing with a VBS script?
> 
> Regards,
> Rollin


A batch file is saved with a ".bat" extension. It uses legal DOS commands.


----------



## Rollin_Again (Sep 4, 2003)

html81993 said:


> A batch file is saved with a ".bat" extension. It uses legal DOS commands.


I understand what a batch file is... I want to know exactly what he is trying to accomplish with his particular batch file. I don't know a whole lot about writing batch files and I don't really understand the syntax he's using but I'm guessing he wants to loop through a directory and copy all text files to a new location? 

If so, he could use a VBS script using FSO (File Scripting Object) to accomplish the same task.

Regards,
Rollin


----------



## ghostdog74 (Dec 7, 2005)

scambro said:


> Hello,
> 
> I have the following batch file that works great, until I happen to execute it on a file with a + in it.
> 
> ...


put quotes between your %%f variable

```
for /r %%f in (*txt) do copy "%%f" "m:\text\%%f"
```


----------



## scambro (Mar 28, 2007)

ghostdog74 said:


> put quotes between your %%f variable
> 
> ```
> for /r %%f in (*txt) do copy "%%f" "m:\text\%%f"
> ```


That did it! When I tried using the quotes before, for some reason I was thinking I needed the quote around the first %%f as well which was screwing it all up.

The point of the batch file is to scan a directory for all text files and include a copy in this other directory that I then use on my webserver.

Thanks for the help!


----------



## gurutech (Apr 23, 2004)

uh, why not just say "copy *.txt m:\text files"


----------

