Solved

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

Posted on 2004-08-23
8
338 Views
Last Modified: 2010-04-17
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
0
Comment
Question by:omegabeta
  • 4
  • 3
8 Comments
 
LVL 9

Expert Comment

by:malharone
ID: 11873963
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
 
LVL 3

Expert Comment

by:kumvjuec
ID: 11874296
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
 
LVL 3

Expert Comment

by:kumvjuec
ID: 11874309
remove the mkdir and time part if you already have the directory with name equal to date only.
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:omegabeta
ID: 11915638
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
 
LVL 3

Expert Comment

by:kumvjuec
ID: 11957601
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
 

Author Comment

by:omegabeta
ID: 11976065
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
 
LVL 3

Accepted Solution

by:
kumvjuec earned 125 total points
ID: 11979504
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
 

Author Comment

by:omegabeta
ID: 12013192
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

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What does != "" mean in programming 8 125
collection output issue 9 59
storing csv file in table variable in Python 2 58
xcopy using a text file to a folder 13 33
A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question