Create a batch fiile

October 9, 2009 at 03:44:51
Specs: Windows Vista

I am trying to create a batch file to run from a text file that creates a folder and then within the folder it creates a blank text file called the town for each entry..


My text file contains something like this:


I would like the outcome to be like this:

Surrey (this is the folder)
- Addlestone.txt
- Addlestonemoor.txt

I hope this makes sense and look forward to receiving any help that anyone has.



See More: Create a batch fiile

Report •

October 9, 2009 at 10:31:32
md surrey
cd surrey
edit asslestone.txt

there is your home work
type in help at a command prompt to figure out how you want to proceed from there.
a "Batch" file is not the best programming language to achive your desired result.

Report •

October 10, 2009 at 09:08:18
Hi there, thanks fr your reply.

At the moment I have a batch file that looks in a text file that looks like this:


And the batch file is this:

@For /F %%I in (List.txt) Do @Type Nul > %%I.txt

This nicely creates a .txt file for each entry in the text file but I would like to use an additional entry at the start of each line of the text file which would create a folder first and then everything that relates to that county would be placed in there as a .txt file and then when it comes to a different county it would create a new folder in the parent directory and fill this with the relevant .txt files. i.e.


Hope this makes sense.

Thanks again.

Report •

October 11, 2009 at 18:17:52
depending on the consistancy of your textfile fields separator (the string-item between the town and the name). If it is
always the same, maybe you could use edit or edlin to
replace the string (it appears to be " | ")
in edlin the commands would be:
1,#R | ^Z\
(the "^z" above is actually control-Z, entered as a control-key
between the target and replacement strings.)
this replaces all the " | " with the "\" for the file to go
to the directory. then use EDIT /70 to replace all the
cr.rets with cr.ret+"xcopy /I nullfile > " (alt-s,r,ctrl-J
tab to the replacement field, enter: ctrljxcopy /i nullfile
then tab to "replace all" and hit <ENTER>. this replaces
all the beginnings of the lines with the xcopy string.)
then save as batchfile. it now looks like this:
xcopy /i nullfile city1\name1
xcopy /i nullfile city1\name2
xcopy /i nullfile city2\name3
create a dummy or null file to give xcopy something to
do. the edlin part could be automated by a batchfile,
but unfort. i don't think there's a way to automate "edit"
(or notepad, short of using VB sendkeys) to do
beginning-of-line replacement (no way to pipe alt-keys).
If you can get something to put a distinctive byte at the
beginning of each line, edlin could be used to do the
whole process by replacing the byte with the xcopy string.

Report •

Related Solutions

October 11, 2009 at 20:26:44
It just seems to me that you you are looking to do something like this. This assumes that each entry is formatted Folder|text.
Also assuming that the text to be read from and the batch file are in the parent directory.

@echo off
for /f "tokens=1-2 delims=|" %%a in (List.txt) do (
if not exist %CD%\%%a\nul md %%a
@Type Nul > %CD%\%%a\%%b.txt

Report •

October 12, 2009 at 14:14:05
Thanks nbrane but being a newbie that really doesn't make sense to me.

Gtaion, that is more of what I think I need but when I run it, it says:
The system cannot find the path specified.

Any more help from you experts?

Thanks a million again.


Report •

October 12, 2009 at 15:37:05
Well off the top of my head the only thing I can think is, if you are using longfilenames, i.e. with spaces, the file path needs to be in double quotes. See if this does the trick.

@echo off
for /f "tokens=1-2 delims=|" %%a in (List.txt) do (
if not exist "%CD%\%%a\nul" md %%a
@Type Nul > "%CD%\%%a\%%b.txt"

Report •

October 12, 2009 at 15:54:01
yeah, you're right. i guess if you're not familiar with edit and edlin, it's just a bunch of gibberish (my post). sorry

relevant to what "almost" works, maybe try replacing "type"
with "xcopy" so that xcopy will create both the dir. and the file in one shot, then it can't whine about not finding the
specified path:

for /f "tokens=1-2 delims=|" %%a in (List.txt) do (

xcopy /i %CD%\%%a\%%b.txt


ps: forgot to add, qtaion is correct about the longfilenames needing quotes, that would still apply.

Report •

Ask Question