Link to home
Start Free TrialLog in
Avatar of dezmay
dezmay

asked on

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.                        
Avatar of gopal_krishna
gopal_krishna

@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
Why not just copy it to the new name and then delete the new file after you upload it?
Avatar of dezmay

ASKER

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.
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
Avatar of dezmay

ASKER

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
try xcopy with the parameters /Q /Y

ATB
Markus
Avatar of dezmay

ASKER

it still ask.
In bat put
ren c:\blah\adminblah\DD20061013.zip D20061113.zip
or

ren c:\blah\adminblah\DD20061113.zip c:\blah\adminblah\D20061013.zip
xcopy D20061109.zip new.zip /Y
Avatar of dezmay

ASKER

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.
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.
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.
/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
Avatar of dezmay

ASKER

@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.
echo N|xcopy D20061109.zip new.zip /Y
Avatar of dezmay

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dezmay

ASKER

accepted and raised point steveGTR thanks for helping all the way. maybe ill bring up my other problem on my next question.

more power