rename-batch / filename of folder

February 19, 2009 at 00:56:26
Specs: Windows XP
I have a folder XYZ20090219in c:\AAA\and in it is a file named 123.idx --> c:\AAA\XYZ20090219\123.idx

I want to rename the file 123.idx into the name of the folder (in this example XYZ20090219.idx), but the name changes (timestamp).
--> c:\AAA\XYZ20090219\XYZ20090219.idx
Tomorrow it will be XYZ20090220.idx in the folder XYZ20090220 ...

In a second step i need to create a file XYZ20090219.txt in the folder above, in c:\AAA

This is a pretty urgent problem and I have no idea how to handle it. So am always happy for replies ;) Even if it's just a solution for the first part. I've been searching for hours now in this forum and couldn't find the answer.

Thanks 1000x!!!

See More: rename-batch / filename of folder

Report •

February 19, 2009 at 02:30:11
hmmm... it's pretty urgent.... sorry, i don't want to stress, but am pretty despaired :(

Report •

February 19, 2009 at 02:47:16
timestamp part:
@echo off
>#.vbs echo wsh.quit Year(date)*10000 +  month(date)*100 + day(date)
cscript//nologo #.vbs
set d=XYZ%errorlevel%
set d

i guess you can figure out the rest.

Report •

February 19, 2009 at 03:07:22
Thank you for your reply. Well, the timestamp gets generated from elswhere. I just need the name of the folder with the timestamp for my file. So i don't have to create it myself. But thank you anyway.

And the rest i have no idea... Sorry... I've been searching for 4 hrs till now :(

you'll make my day for helping out ;)

Report •

Related Solutions

February 19, 2009 at 04:26:01
to rename every 123.idx file located at XYZ* folder to XYZ*.idx file. and create a XYZ*.txt file. is it this what you are looking for?

@echo off
pushd c:\AAA
for /f "tokens=*" %%a in ('dir/b/ad XYZ*') do (
>%%a.txt ren "%%a\123.idx" "%%a.idx"

Report •

February 19, 2009 at 04:53:27
YOU ARE A HERO :o) thank you sooo much, it works exactly how i wanted it!!!

i will give the second part a try now
(as soon as this *.idx-file has been renamed i have to create a file with the same name but *.rdy - in the folder above / in this example c:\AAA)

if you know the solution without much trouble of course it would save me lots of time, but i don't want to create too much hassle and am already so grateful for what i got! :)

Report •

February 19, 2009 at 04:59:08
oh sorry. i just realized that your solution already contains the second step. wow. all complete, all perfect! what a day. thank you 1000x!!! :o) i really appreciate it!

Report •

February 19, 2009 at 05:50:03
Save this into a batch file, eg, test.cmd in the C:\AAA folder

--copy and paste from line below--
@echo off

rem -- this line just list the directory contents
dir C:\AAA\XYZ%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%

rem -- this line show your current date format and you will need to adjust the position below, eg, %DATE:~10,4% will extract the 4 chars starting from 10th char. The date format I'm using is 'Thu 19/02/2009'
echo %DATE%

rem -- this line check if the 123.idx file exist and rename it according to date format

if exist C:\AAA\XYZ%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%\123.idx ren C:\AAA\XYZ%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%\123.idx XYZ%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%.idx

rem -- show directory content again after rename
dir C:\AAA\XYZ%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%

--until here--


Report •

February 19, 2009 at 23:09:14
GREAT! Wow, thank you both for all the details! I could solve what i wanted perfectly well - of course only with your brilliant help :)

Report •

Ask Question