Rename a file to old filename...

Operating system: WinXP, Win2K, Win2003

Scenario: I have this file that everytime i upload to the server i change the name to todays date.
         
               Ex. OldFilename = D20061013.zip
                    NewFilename = D20061113.zip <--- todays date.

Filename format: DYYYYMMDD.zip                          
wherein: D = Download
              YYYY = Year
              MM = Month
              DD = Date

Question: After i rename it to todays date after i upload it to my server. How will i rename it back to it's old filename in the exact format using a bacthfile?

Anyone who will help. Many thanks and more power.                        
dezmayAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
SteveGTRConnect With a Mentor Commented:
It loops and does nothing... What does that mean? Does it do it for this?

echo N|xcopy D20061109.zip new.zip /Y

I'd say that would be pretty strange behaviour. Are you taking about some other code?

As for your other request. Here's what I'd suggest:

@echo off

setlocal

call :GETDATEPARTS "%date%"

copy backup_metro.db backup_%mm%%dd%%yy%.db

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF

0
 
gopal_krishnaCommented:
@ECHO OFF
  IF (GOTO:)==(%1) %1%2 {Subroutine-Handler}


  CALL %0 GOTO: _DTM
  :: Remove ECHO.{demo!} to activate command
  ECHO.{demo!}MD C:\%DT%
  SET DT=


  GOTO EOF {=Subroutine-section-below=}
  :_DTM (Usage: CALL %0 GOTO: _DTM)
  ECHO.e100 e8 0 0 80 c3 2 88 dc cd 1a 89 97 1e 1 89 8f 22 1 c3>%TEMP%.\_DT.BAT
  FOR %%C IN (g d121L7 q) DO ECHO.%%C>>%TEMP%.\_DT.BAT
  TYPE %TEMP%.\_DT.BAT|debug|find ":">%TEMP%.\_DT.BAT
  FOR %%C IN (e100'%%1'20'%%2'20'%%3'20 w q) DO ECHO.%%C>>%TEMP%.\_DT.BAT
  TYPE %TEMP%.\_DT.BAT|debug %TEMP%.\_DT.BAT>NUL
  CALL %TEMP%.\_DT.BAT %0 GOTO: 1_DTM
  DEL %TEMP%.\_DT.BAT
  GOTO EOF
  :1_DTM
  SET DT=%8%5%4


  :EOF {End-of-file}


Cut and paste and save as batch file and you can rename the file or folder.

Regards
Gopal Krishna K
0
 
SteveGTRCommented:
Why not just copy it to the new name and then delete the new file after you upload it?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
dezmayAuthor Commented:
that is a good idea but does a content of a zip file can be copied inside a named zip file also on a command line? then how?

many thanks.
0
 
SteveGTRCommented:
It can it is simple a file like any other file. Just as you can copy an executable to another name. It would be done like this:

copy file1.zip file2.zip
0
 
dezmayAuthor Commented:
when you have given me the idea i already did it like the example you gave but the problem is the new zip created is only 1kb meaning it does not copy the content.

what i did is

copy D20061109.zip new.zip

i found also the same way using xcopy and it do copy the content

example

xcopy D20061109.zip new.zip

is there a way for the xcopy not to prompt anything?

thanks
0
 
MarkusKolbeckCommented:
try xcopy with the parameters /Q /Y

ATB
Markus
0
 
dezmayAuthor Commented:
it still ask.
0
 
MarkWYnneCommented:
In bat put
ren c:\blah\adminblah\DD20061013.zip D20061113.zip
0
 
MarkWYnneCommented:
or

ren c:\blah\adminblah\DD20061113.zip c:\blah\adminblah\D20061013.zip
0
 
SteveGTRCommented:
xcopy D20061109.zip new.zip /Y
0
 
dezmayAuthor Commented:
it still ask.

ok can anyone make a batch for this?

ex.

D20061109.zip renamed to current date ex. D20061115.zip


and another batchfile to rename it to its originale name.

many thanks.
0
 
SteveGTRCommented:
So if you type this on the command line. What does it say exactly:

xcopy D20061109.zip new.zip /Y

If the D20061109.zip does not exist. Then create it prior to running this test.
0
 
expexchuserCommented:
Try vbscript instead of old school DOS batch.  Anyone up to the challenge of making the script?  I'm at work and trying to limit my time on this site today.  You could use this for inspiration:
http://www.scriptinganswers.com/vault/Files%20and%20Folders/Rotate%20IIS%20Log%20Files.zip

It's an IIS log rotation script by scripting expert Don Jones.
0
 
expexchuserCommented:
/y is the xcopy switch to supress overwrite prompts.

Otherwise whenever I use xcopy, I use these switches:
/h - copy hidden and system files
/i - assumes destination is a directory if it doesn't exist
/c - continue copying even with errors
/k - copies attributes
/e - copies directories and subdirectories
/o - copy acl ownerships
/r - overwrites read-only files
/y - no prompts
0
 
dezmayAuthor Commented:
@steveGTR

it ask if its destination is a file or a folder. i already put the /Y put it still ask. is there a switch to let xcopy know the destination is a file?

many thanks.
0
 
SteveGTRCommented:
echo N|xcopy D20061109.zip new.zip /Y
0
 
dezmayAuthor Commented:
it loops and does nothing. im using win2k3.

ok here is my last question. i have this backup

ex.

backup_metro.db

how will i rename this filename to its present date using batch in a windows 2003 dos?

ex. backup_metro.db change to backup_MMDDYYYY.db

wherein: MM = Month
              DD = Date
              YYYY = Year

anyone can help me?
0
 
dezmayAuthor Commented:
accepted and raised point steveGTR thanks for helping all the way. maybe ill bring up my other problem on my next question.

more power
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.