Re: Need help with batch files!
- From: Matt G <MattG@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 7 Nov 2008 03:58:00 -0800
"Pegasus (MVP)" wrote:
"Matt G" <MattG@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A13468D5-0D86-4D31-A69F-99FC7A697D51@xxxxxxxxxxxxxxxx
"Pegasus (MVP)" wrote:
"Matt G" <MattG@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D151B3F5-B316-4422-9324-7EA6D7F21F41@xxxxxxxxxxxxxxxx
I need to download files on various days from various clients for
specific
dates. I currently manually edit each line of code each time I
download.
I
need help with the "set" command so I'll only have to change the
"plantid",
"date", and "day" once at the beginning of the file. Here's what I
tried
but
it doesn't work:
echo off
color 17
set plantid = 0091
set datenow = 20081103
set day = Monday
set localroot=\\co-atl-rw-01\rs
rem set localroot=d:
copy %localroot%\rs_input\D1_%plantid%_*%datenow%.txt
%localroot%\rs_input\D1_%plantid%_%day%_%datenow%.txt
copy %localroot%\rs_input\M1_%plantid%_*%datenow%.txt
%localroot%\rs_input\M1_%plantid%_%day%_%datenow%.txt
copy %localroot%\rs_input\M2_%plantid%_*%datenow%.txt
%localroot%\rs_input\M2_%plantid%_%day%_%datenow%.txt
copy %localroot%\rs_input\FL_%plantid%_*%datenow%.txt
%localroot%\rs_input\FL_%plantid%_%day%_%datenow%.txt
Any suggestions?
You cannot have wildcards in the path component of a copy command. There
could be a way around this problem - try to describe in functional terms
what you're trying to do.
On the server there are files specific to plantid and date. Each plant
has several files for each date. I want to get all the files for a
specific plant for a specifc date and copy them to my computer with
specific names:
copy \\co-atl-rw-01\rs\FL_0091_*20081106.txt
d:\rs_input\FL_0091_Thursday_20081106.txt
In your original code you never actually said what "it does not work"
means - please supply full details.
I modified the original code like so:
@echo off
set plantid = 0091
set datenow = 20081103
set day = Monday
set localroot=\\co-atl-rw-01\rs
rem set localroot=d:
echo copy %localroot%\rs_input\D1_%plantid%_*%datenow%.txt
%localroot%\rs_input\D1_%plantid%_%day%_%datenow%.txt
echo copy %localroot%\rs_input\M1_%plantid%_*%datenow%.txt
%localroot%\rs_input\M1_%plantid%_%day%_%datenow%.txt
echo copy %localroot%\rs_input\M2_%plantid%_*%datenow%.txt
%localroot%\rs_input\M2_%plantid%_%day%_%datenow%.txt
echo copy %localroot%\rs_input\FL_%plantid%_*%datenow%.txt
%localroot%\rs_input\FL_%plantid%_%day%_%datenow%.txt
From this code I notice a few things:
- My initial claim about you having a wildcard in the path was incorrect.
Your wildcards are correctly placed.
- The target machine is the same as the source machine.
- The batch file will pause if the target file already exists. You need to
add the /Y switch to prevent this.
- Having a space in front of your variables is not a good idea. It will
cause lots of problems. You should code them like so:
set plantid=0091
set datenow=20081103
set day=Monday
When I write the script as you have it here the window opens for a split second then closes. The "not working" part from before was the program would search for the file but not place the variables in the file name. It would look for:
FL_*.txt instead of FL_0091_*20081106.txt
Should I have this saved as .bat or .cmd?
.
- Follow-Ups:
- Re: Need help with batch files!
- From: Pegasus \(MVP\)
- Re: Need help with batch files!
- References:
- Need help with batch files!
- From: Matt G
- Re: Need help with batch files!
- From: Pegasus \(MVP\)
- Re: Need help with batch files!
- From: Matt G
- Re: Need help with batch files!
- From: Pegasus \(MVP\)
- Need help with batch files!
- Prev by Date: Disabling Update notifications
- Next by Date: Std Users, Update Files?
- Previous by thread: Re: Need help with batch files!
- Next by thread: Re: Need help with batch files!
- Index(es):
Relevant Pages
|
Loading