Re: Need help with batch files!





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



Relevant Pages

  • Re: Need help with batch files!
    ... "Pegasus (MVP)" wrote: ... You cannot have wildcards in the path component of a copy command. ...
    (microsoft.public.windows.server.general)
  • Re: Sharing and Security on File Share
    ... from AD to enure I didn't have a typo in the command line you requested. ... "Pegasus (MVP)" wrote: ... net user rogene>> c:\test.txt ...
    (microsoft.public.windows.file_system)
  • Re: file sharing only works for some files, not all
    ... Pegasus (MVP) wrote: ... indicate that permissions are used with domains...which is why I can't ... If you now open another Command Prompt and type this ...
    (microsoft.public.windowsxp.general)
  • Re: Need help with batch files!
    ... "Pegasus (MVP)" wrote: ... You cannot have wildcards in the path component of a copy command. ...
    (microsoft.public.windows.server.general)
  • Re: Copying Files Problems
    ... "Pegasus (MVP)" wrote: ... Use the copy command to copy small.bin and large.bin to M:\. ... of 2 MBytes and one of 20 MBytes. ...
    (microsoft.public.windowsxp.general)

Loading