Can't rename files.

Toshiba Satellite a200-st2041 notebook
July 24, 2009 at 05:21:48
Specs: Windows Vista
I want my batch file to rename combined.txt to the current date.
So far i have:
ren combined.txt %date%.txt

I just get "The syntax of your command is incorrect."
I know what this means but i don't know what's wrong with it.
Thanks


See More: Cant rename files.

Report •


#1
July 24, 2009 at 05:38:38
Many, if not most, %date% vars have chars which are illegal in file names.

\/:

and others


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
July 24, 2009 at 11:34:17
Could you tell me a way I could reame the file to the current date?

Report •

#3
July 25, 2009 at 04:32:42
@echo off & setLocal enableDELAYedexpansion

@echo off > d.d

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set DD=0%%a
for %%a in ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set DD=%%a

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday

month
for %%a in (1 2 3 4 5 6 7 8 9 ) do if errorlevel %%a set MM=0%%a
for %%a in ( 10 11 12) do if errorlevel %%a set MM=%%a

year
if errorlevel 215 set YYYY=2007
if errorlevel 216 set YYYY=2008
if errorlevel 217 set YYYY=2009
if errorlevel 218 set YYYY=2010
if errorlevel 219 set YYYY=2011
if errorlevel 220 set YYYY=2012

set YYYYMMDD=%YYYY%%MM%%DD%

del day.com
del month.com
del year.com
del dat.com

::============================ DONE YMD12 ==========================

ren combined.txt %YYYYMMDD%.txt


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
July 25, 2009 at 07:55:02
I put this in my batch script and wrote pause after so i could see the error...
it was, The system cannot find the file specified.
Any ideas?

"An open mind leaves a chance for someone to drop a worthwhile thought into it."


Report •

#5
July 25, 2009 at 12:49:52
or you could try this

@echo off
set noob=%date%
set noob=%noob:/=-%
ren [drive:][path]combined.txt %noob%
pause


Report •

#6
July 26, 2009 at 01:42:05
So is combined.txt there?


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#7
July 26, 2009 at 13:10:55
The file is definetly there, so I was confused when screwed124816's suggestion turned up the error, The system cannot find the file specified.

This was the way I edited the code to put in:
-----------------------------------------------------------------------------------------
@echo off
set noob=%date%
set noob=%noob:/=-%
ren combined.txt %noob%
pause
-----------------------------------------------------------------------------------------
(I took out the file path and drive because the file is in the same directory as the batch)

"An open mind leaves a chance for someone to drop a worthwhile thought into it."


Report •


Ask Question