Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
ì´ìš©ë¯¼
- Posts: 5
- Joined: 17 Mar 2012 13:24
#1
Post
by ì´ìš©ë¯¼ » 17 Mar 2012 13:27
What I want to do is basically write information to X amount of files at the same time. I have a script that is working at the moment,
but it misses out the files that have spaces in their name. If anyone can help me, it'd be greatly appreciated.
Here is the script:
Code: Select all
@echo off & setLocal EnableDELAYedeXpansion
for /f "tokens=* delims= " %%a in ('dir/b *.cfg') do (
>> # echo.Test=0
for /f "tokens=* delims= " %%i in (%%a) do (
>> # echo.%%i
)
move /y # %%a
)
-
aGerman
- Expert
- Posts: 4740
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 17 Mar 2012 13:43
Not exactly sure what you're trying to do.
Code: Select all
for /f "delims=" %%a in ('dir/b *.cfg') do (
># echo(Test=0
for /f "usebackq tokens=* delims= " %%i in ("%%a") do (
>># echo(%%i
)
move /y # "%%a"
)
If you only want to prepend the line "Test=0" you don't need the 2nd loop.
Code: Select all
for /f "delims=" %%a in ('dir/b *.cfg') do (
># echo(Test=0
>># type "%%a"
move /y # "%%a"
)
Regards
aGerman
-
ì´ìš©ë¯¼
- Posts: 5
- Joined: 17 Mar 2012 13:24
#3
Post
by ì´ìš©ë¯¼ » 17 Mar 2012 13:46
Basically, I have a folder that contains X amount of CFG files. Some of the file names don't have spaces, some do have spaces. When I run the bat, it works correctly by prepending the line Test=0 into the files that don't have spaces, but it does not prepend the Test=0 line with the files that have spaces. I want it to prepend the Test=0 into all files, with and without spaces.
Thank you for your reply, and any further help would greatly be appreciated.
-
ì´ìš©ë¯¼
- Posts: 5
- Joined: 17 Mar 2012 13:24
#4
Post
by ì´ìš©ë¯¼ » 17 Mar 2012 13:52
Ok, it now seems to work fine (even with spaces) from using the code you posted above, but now I have a question on how to make it add it to the 'end' of the file. It is currently adding the text to the top of the file, and I want it added to the bottom.
-
aGerman
- Expert
- Posts: 4740
- Joined: 22 Jan 2010 18:01
- Location: Germany
#5
Post
by aGerman » 17 Mar 2012 13:55
That's much easier.
Code: Select all
for /f "delims=" %%a in ('dir/b *.cfg') do >>"%%a" echo(Test=0
Regards
aGerman
-
ì´ìš©ë¯¼
- Posts: 5
- Joined: 17 Mar 2012 13:24
#6
Post
by ì´ìš©ë¯¼ » 17 Mar 2012 14:06
Thank you, and what method would I use to prepend more than 1 line?
Code: Select all
for /f "delims=" %%a in ('dir/b *.cfg') do >>"%%a" echo(Test=0 echo(Test2=0
????
-
aGerman
- Expert
- Posts: 4740
- Joined: 22 Jan 2010 18:01
- Location: Germany
#7
Post
by aGerman » 17 Mar 2012 14:11
I assume you mean
appending more than one line.
Code: Select all
for /f "delims=" %%a in ('dir/b *.cfg') do (
>>"%%a" echo(Test=0
>>"%%a" echo(Test2=0
)
Regards
aGerman
-
ì´ìš©ë¯¼
- Posts: 5
- Joined: 17 Mar 2012 13:24
#8
Post
by ì´ìš©ë¯¼ » 17 Mar 2012 14:12
Yeah, I just figured that out now

Thank you for all your help. It is greatly appreciated.