Solved

Rename a file to old filename...

Posted on 2006-11-12
19
508 Views
Last Modified: 2008-01-09
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.                        
0
Comment
Question by:dezmay
  • 7
  • 6
  • 2
  • +3
19 Comments
 
LVL 9

Expert Comment

by:gopal_krishna
ID: 17927709
@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
 
LVL 30

Expert Comment

by:SteveGTR
ID: 17927787
Why not just copy it to the new name and then delete the new file after you upload it?
0
 

Author Comment

by:dezmay
ID: 17927885
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
 
LVL 30

Expert Comment

by:SteveGTR
ID: 17927894
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
 

Author Comment

by:dezmay
ID: 17928014
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
 
LVL 5

Expert Comment

by:MarkusKolbeck
ID: 17928097
try xcopy with the parameters /Q /Y

ATB
Markus
0
 

Author Comment

by:dezmay
ID: 17928547
it still ask.
0
 
LVL 3

Expert Comment

by:MarkWYnne
ID: 17929204
In bat put
ren c:\blah\adminblah\DD20061013.zip D20061113.zip
0
 
LVL 3

Expert Comment

by:MarkWYnne
ID: 17929227
or

ren c:\blah\adminblah\DD20061113.zip c:\blah\adminblah\D20061013.zip
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 30

Expert Comment

by:SteveGTR
ID: 17929565
xcopy D20061109.zip new.zip /Y
0
 

Author Comment

by:dezmay
ID: 17943868
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
 
LVL 30

Expert Comment

by:SteveGTR
ID: 17944589
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
 
LVL 4

Expert Comment

by:expexchuser
ID: 17948399
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
 
LVL 4

Expert Comment

by:expexchuser
ID: 17949113
/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
 

Author Comment

by:dezmay
ID: 17962613
@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
 
LVL 30

Expert Comment

by:SteveGTR
ID: 17965655
echo N|xcopy D20061109.zip new.zip /Y
0
 

Author Comment

by:dezmay
ID: 18006467
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
 
LVL 30

Accepted Solution

by:
SteveGTR earned 70 total points
ID: 18009122
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
 

Author Comment

by:dezmay
ID: 18042657
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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Many people tend to confuse the function of a virus with the one of adware, this misunderstanding of the basic of what each software is and how it operates causes users and organizations to take the wrong security measures that would protect them ag…
Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now