Save a file with a particular name using a .bat file

I want to save a file with a particular name using a .bat file
Something like this:

copy \\comp1\directory\*.*  \\server\date

where date can be A1082004  (A=0, B=1,C=2, D=3)
So I must save in a particular directory coresponding to the partcular day(day= today -1)

Thanks
omegabetaAsked:
Who is Participating?
 
kumvjuecCommented:
hi omega

use this

if %day% lss 10 (set day=A)
if %day% lss 20 ( if %day% gtr 10 (set day=B))

btw, you should also take care of the conditions where day=10.
for <=, the symbol is leq
for >=, the symbol is geq.

Hope your work will get done now:)
0
 
malharoneCommented:
The sample below writes the file as "OrdersReport_8-23-2004_1.09.10_AM.xml"

Sub FileSave( sContents )
      dim FSO
      dim fOut
      dim fDir
      dim fOutPath
      dim fName
      dim fDate
      On Error Resume Next
 
      fOutPath = "c:\temp\"
      fDate = Replace( Now(), "/", "-" )
      fDate = Replace( fDate, ":", "." )
      fDate = Replace( fDate, " ", "_" )
      fName = "OrdersReport_" & fDate & ".xml"

      set FSO = CreateObject ("Scripting.FileSystemObject")
      set fOut = FSO.CreateTextFile(fOutPath & fName )
      set fOut = FSO.GetFile(fOutPath & fName )

      ' open output file for writing as ANSI
      set sOut = fOut.OpenAsTextStream(2, 0 )

      ' write the file out and delete the input file
      sOut.write sContents
      sOut.Close
      set fOut = nothing
      set fDir = nothing
      set FSO = nothing
End Sub
0
 
kumvjuecCommented:
hi,
put this in your batch file. I hope you can customize it to your needs :).
Almost similar question is also here http://www.experts-exchange.com/Programming/Q_21102859.html

###############copyfiles.bat####
@echo off
set date1=%date:~-10%
set date2=%date1:/=%

set time1=%time: =0%
set time2=%time1::=%
set time3=%time2:~0,4%

set dirname=%date2%_%time3%
mkdir c:\images\%dirname%

copy h:\dcim\101msdcf\* c:\images\%dirname%\
##############
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kumvjuecCommented:
remove the mkdir and time part if you already have the directory with name equal to date only.
0
 
omegabetaAuthor Commented:
For kumvjuec,

Please explain me the following:
set date1=%date:~-10% extract the last 10 charactes from date (~ what reprezent ?)
set date2=%date1:/=% ?

set time1=%time: =0% ?
set time2=%time1::=% ?
set time3=%time2:~0,4%  extract first 4 characters

Thanks
0
 
kumvjuecCommented:
hi omega
sorry, i was out on vacation :)

All the set statements just define a new variable which act as intermediate. I have used them just for the sake of clarity. If you want to see their values, you can use
echo %time1%
for printing the values on the screen. The above statement for instance will print the value of variable "time1"
For help on ~, use
set /? on the command prompt. just pasting some of it...

    %PATH:~10,5%
would expand the PATH environment variable, and then use only the 5
characters that begin at the 11th (offset 10) character of the expanded
result.  If the length is not specified, then it defaults to the
remainder of the variable value.  If either number (offset or length) is
negative, then the number used is the length of the environment variable
value added to the offset or length specified.

    %PATH:~-10%
would extract the last 10 characters of the PATH variable.

    %PATH:~0,-2%
would extract all but the last 2 characters of the PATH variable.
0
 
omegabetaAuthor Commented:
OK kumvjuec . I made: set day=%date:~-10,2%
But how can I make a comparition such as:

f %day% <10 set day=A
if %day% <20 and %day% >10 set day=B
if %day% <30 and %day% >20 set day=C
if %day% >30 set day=D

Thanks
0
 
omegabetaAuthor Commented:
Thanks kumvjuec. Maybe you can tell can can I delay a message on the screen. Neither TIMEOUTn nor SLEEP n doesn't work. How can I use a FOR loop for example ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.