1.

Solve : Batch only file name... from a?

Answer»

Hi,
please help
I ´ve 2 files:
in d:\Temp\Testing\
Docs20120101.csv
marti.rar

and i want a batch that rename the file marti.rar to Docs20120101.rar(like de csv file) it´s possible?
everday is a direrente file whit a diferente date()..
Thanks.Rename marti.rar Docs20120101.rarFor YYYYMMDD form.
Code: [Select]ren d:\Temp\Testing\marti.rar d:\Temp\Testing\Docs%date:~6%%date:~3,2%%date:~0,2%.rar

For YYYYDDMM form.
Code: [Select]ren d:\Temp\Testing\marti.rar d:\Temp\Testing\Docs%date:~6%%date:~0,2%%date:~3,2%.rar

Quote from: Sirim on January 06, 2012, 05:48:04 AM

For YYYYMMDD form.
Code: [Select]ren d:\Temp\Testing\marti.rar d:\Temp\Testing\Docs%date:~6%%date:~3,2%%date:~0,2%.rar

For YYYYDDMM form.
Code: [Select]ren d:\Temp\Testing\marti.rar d:\Temp\Testing\Docs%date:~6%%date:~0,2%%date:~3,2%.rar

Your offset is off by a few characters. For your first one it should be Code: [Select]ren d:\Temp\Testing\marti.rar d:\Temp\Testing\Docs%date:~10%%date:~4,2%%date:~7,2%.rarand your second should be Code: [Select]ren d:\Temp\Testing\marti.rar d:\Temp\Testing\Docs%date:~10%%date:~7,2%%date:~4,2%.rar
Unless your date variable expands differently than mine..

Code: [Select]c:\>echo %date%
Fri 01/06/2012

c:\> Quote from: Raven19528 on January 06, 2012, 10:27:27 AM

Unless your date variable expands differently than mine..


You mean like this?

Code: [Select]C:>echo %date%
06/01/2012 Quote from: Salmon Trout on January 06, 2012, 10:47:00 AM
You mean like this?

Code: [Select]C:>echo %date%
06/01/2012

Yep. Just like that. Maybe it would be better to explain the offset and parsing aspect of variables rather than try to assume how the OPs date variable expands. Unless the OP would like to show us how the date variable expands on his/her CPU.I made a mistake in my first answer, such that it would not work whatever the %date% EXPANSION. Ren does not expect a path when specifying the new file name. The code below is correct.

My %date% expands just like Salmon Trout's.

Something that would work on either of the expansions mentioned so far (ALTHOUGH not on any others):

On UK systems for YYYYMMDD or on US systems for YYYYDDMM.
Code: [Select]if "%date%"=="%date: =%" (ren d:\Temp\Testing\marti.rar Docs%date:~6%%date:~3,2%%date:~0,2%.rar) else ren d:\Temp\Testing\marti.rar Docs%date:~10%%date:~7,2%%date:~4,2%.rar
On UK systems for YYYYDDMM or on US systems for YYYYMMDD.
Code: [Select]if "%date%"=="%date: =%" (ren d:\Temp\Testing\marti.rar Docs%date:~6%%date:~0,2%%date:~3,2%.rar) else ren d:\Temp\Testing\marti.rar Docs%date:~10%%date:~4,2%%date:~7,2%.rar
I AGREE that it would be a lot easier if the OP showed their %date% expansion.Hybrid script works in any locale

Code: [Select]echo off
echo Wscript.echo eval(WScript.Arguments(0)) > evaluate.vbs
for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "YEAR  (date)" ' ) do set yyyy=%%A
for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "Month (date)" ' ) do set mm=%%A
for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "Day   (date)" ' ) do set dd=%%A
del evaluate.vbs
if %mm% lss 10 set mm=0%mm%
if %dd% lss 10 set dd=0%dd%
echo yyyy       %yyyy%
echo mm         %mm%
echo dd         %dd%
echo yyyymmdd   %yyyy%%mm%%dd%
echo yyyy-mm-dd %yyyy%-%mm%-%dd%
echo mm/dd/yyyy %mm%/%dd%/%yyyy%

set examplevar=%yyyy%%mm%%dd%


Code: [Select]yyyy       2012
mm         01
dd         06
yyyymmdd   20120106
yyyy-mm-dd 2012-01-06
mm/dd/yyyy 01/06/2012
There is a lot of stuff here that I don't understand. I thought you just wanted to rename something. If so I would do it this way:

Create a batch file. We will call it 'rename.bat'

The file would look like this:

ren marti.rar Doc2012%1

I am not sure if I have the wording correct as I can't see your message, but you get the idea. When you run the file simply enter 'rename mmdd' where mmdd is the month and day. (or day and month if you wan this order.

Since there is a lot of other stuff POSTED in posts to your message I am not sure if this is what you want. If you already have a batchfile to run the other programs you can just include this in it and enter the mmdd info when you run that batch file.

Hope it helps
Jim, the O/P has not posted back in over a month so we will never know what solved their problem.


Discussion

No Comment Found