🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #7996

Re: HELP: Shell script

#7996
From: John Savage
Date: Mon, 15 Jan 1996 00:00
47 lines
2841 bytes
rclark@iquest.net (Robert B. Clark) writes:
]swan@unlgrad1.unl.edu (Shu-Mei Wan) wrote:
]>I have 100 files need to copy.
]>Since it is routine work, I heard that we can use the batch file to
]>make it more efficiently.  I hope somebody out there can help me.  The
]>file's names are "filename1, filename2, ..., filename100" will go to the
]>directories name "dir1, dir2,..., dir100".  That is
]>
]> copy a:\filename1 c:\dir1
]> copy a:\filename2 c:\dir2
]> copy a:\filename3 c:\dir3
]
]rem The 'file' evar holds the base name of the file to be copied
]set file=foo
]for %a in (1 2 3 4 5 6 7 8 9) do copy %file%%%a c:\dir%%a
]for %a in (0 1 2 3 4 5 6 7 8 9) do copy %file%1%%a c:\dir1%%a
]for %a in (0 1 2 3 4 5 6 7 8 9) do copy %file%2%%a c:\dir2%%a
]for %a in (0 1 2 3 4 5 6 7 8 9) do copy %file%3%%a c:\dir3%%a
]...
]for %a in (0 1 2 3 4 5 6 7 8 9) do copy %file%9%%a c:\dir9%%a
]copy %file%100 c:\dir100
]set file=
]
]This will copy files FOO1, FOO2, .. FOO100 to directories C:\DIR1,
]C:\DIR2, ... C:\DIR100, assuming they exist.
]
]Could be optimized, but it's easy enough to cut and paste the for loops,
]and the logic should be easier to follow in this form.

You're quite right, often it makes more sense to use the creative
abilities of your editor in producing a batch file, than to resort
to imaginative [mis]use of MSDOS commands.

However, in this particular case, I think it's possible to accomplish
the task in just two lines (the second being one long line):

for %%i in (1 2 3 4 5 6 7 8 9) do xcopy a:filen%%i%%j dir%%i%%j\

for %%i in (1 2 3 4 5 6 7 8 9) do command/c for %%j in (0 1 2 3 4 5 6 7
8 9) do xcopy a:filen%%i%%j dir%%i%%j\

With care, you should just narrowly escape the MSDOS limitation of a
command line length of about 127 chars. (Execute this as a .bat so
that the prompt doesn't rob you of a few chars, and if necessary you
can shorten the filenames on A: with RENAME, e.g., RENAME filen* f* )
--
John Savage               koala@sydney.dialix.com.au
Technical Details
Message-ID: <4dd97m$mkl$1@sydney.DIALix.oz.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <4c7kpk$okk@crcnis3.unl.edu> <30eaf7b0.11414238@news.iquest.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10f6aa,ae54db66b0a319f2
X-Google-Attributes: gid10f6aa,public
X-Google-Thread: 10d683,c771ac28ef8e4346,start
X-Google-Attributes: gid10d683,public
X-Google-Thread: f71eb,c771ac28ef8e4346,start
X-Google-Attributes: gidf71eb,public
X-Google-Thread: 104805,c771ac28ef8e4346,start
X-Google-Attributes: gid104805,public
From: John Savage <koala@sydney.dialix.com.au>
Subject: Re: HELP: Shell script
Date: 1996/01/15
Message-ID: <4dd97m$mkl$1@sydney.DIALix.oz.au>
X-Deja-AN: 135624945
sender: koala@sydney.DIALix.oz.au
references: <4c7kpk$okk@crcnis3.unl.edu> <30eaf7b0.11414238@news.iquest.net>
organization: Gumleaf Smoke Signals Telegraph Co.
newsgroups: comp.os.msdos.programmer,comp.os.msdos.misc,aus.computers.ibm-pc,alt.msdos.batch