Computing.Net > Forums > Programming > Create a batch fiile

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Create a batch fiile

Reply to Message Icon

Name: wwwredback
Date: October 9, 2009 at 03:44:51 Pacific
OS: Windows Vista
Subcategory: Batch
Tags: Batch file, text file
Comment:

Hello,

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..

i.e

My text file contains something like this:

Surrey|Addlestone
Surrey|Addlestonemoor

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.

Thanks

James



Sponsored Link
Ads by Google

Response Number 1
Name: OjorlE
Date: October 9, 2009 at 10:31:32 Pacific
Reply:

c:
cd\
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.


0

Response Number 2
Name: wwwredback
Date: October 10, 2009 at 09:08:18 Pacific
Reply:

Hi there, thanks fr your reply.

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

Abbey-Wood
Acton
Addington
Aldgate
Aldwych
Archway
Ashford
Balham

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.

London|Abbey-Wood
London|Acton
Surrey|Addington
LondonAldgate
Surrey|Aldwych
Surrey|Archway
LondonAshford
Surrey|Balham

Hope this makes sense.

Thanks again.


0

Response Number 3
Name: nbrane
Date: October 11, 2009 at 18:17:52 Pacific
Reply:

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\
e
(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.


0

Response Number 4
Name: gtaion
Date: October 11, 2009 at 20:26:44 Pacific
Reply:

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
)


0

Response Number 5
Name: wwwredback
Date: October 12, 2009 at 14:14:05 Pacific
Reply:

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.

James.


0

Related Posts

See More



Response Number 6
Name: gtaion
Date: October 12, 2009 at 15:37:05 Pacific
Reply:

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"
)


0

Response Number 7
Name: nbrane
Date: October 12, 2009 at 15:54:01 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

To get the last 10 lines ... To check if a string is p...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Create a batch fiile

Creating a batch using a batch www.computing.net/answers/programming/creating-a-batch-using-a-batch/15721.html

how to create a batch 837 file www.computing.net/answers/programming/how-to-create-a-batch-837-file/15547.html

Create a batch file to rename text www.computing.net/answers/programming/create-a-batch-file-to-rename-text/14900.html