How can I rename a directory quickly in a script?

T

Todd

Hi Guys,

I have a batch script that rotates directory names.

rename %BkPath%\backup%X% backup%Y%

Problem: I do not seem to just be changing the name of the directory,
I seem to be copying all the contents of the old directory to
the new directory. It works, but it can take up to 20 minutes
as there is a lot of data in each backup set.

Is there a way to just change the name of the directory and avoid
the time delay of all the copying?

Many thanks,
-T
 
P

Paul

Todd said:
Hi Guys,

I have a batch script that rotates directory names.

rename %BkPath%\backup%X% backup%Y%

Problem: I do not seem to just be changing the name of the directory,
I seem to be copying all the contents of the old directory to
the new directory. It works, but it can take up to 20 minutes
as there is a lot of data in each backup set.

Is there a way to just change the name of the directory and avoid
the time delay of all the copying?

Many thanks,
-T

If you do this

rename C:\testdir\test.txt C:\testdir\newname.txt

that can work, because the data clusters are already on the
C: partition, and all that needs correcting, is the path to get
there.

If you do this

rename C:\testdir\test.txt D:\somedir\newname.txt

then that involves two independent partitions, and the only
way to get the data clusters there is by copying them. No
amount of fiddling the path or file pointer info can fix it.
You pay "full price" in that case.

If you had a Partition Manager, and you "merged" two partitions
which were next to one another on the same disk, that might be
an example of "crossing the boundary". I've never done a merge,
and have no idea how it is actually achieved (the mechanics of merging).
But you never know, it might be more economical than a plain copy.
Since it changes the state of the system, it's hardly a replacement
for what you're trying to do.

Paul
 
T

Todd

If you do this

rename C:\testdir\test.txt C:\testdir\newname.txt

that can work, because the data clusters are already on the
C: partition, and all that needs correcting, is the path to get
there.

If you do this

rename C:\testdir\test.txt D:\somedir\newname.txt

The expanded script look like

rename d:\MyBackup\backup1 d:\MyBackups\backup2

I am renaming to the same drive

I am renaming directories, not files. The directories are full
of stuff. Takes about 20 minutes to rename. Bummer.
 
M

Mayayana

I don't have much experience with DOS batch files,
so I don't know if maybe there's a separate problem.
It seems like what you're doing should work OK.
But you might try this in a .vbs file:

Dim FSO, oFol
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFol = FSO.GetFolder("D:\MyBackup\backup1")
oFol.Name = "backup2"
Set oFol = Nothing
Set FSO = Nothing

I renamed a 767 MB folder instantly with that VBS.
If that doesn't work instantly for you then probably
you've got something interfering. (AV? I don' know.)
 
P

Paul

Todd said:
The expanded script look like

rename d:\MyBackup\backup1 d:\MyBackups\backup2

I am renaming to the same drive

I am renaming directories, not files. The directories are full
of stuff. Takes about 20 minutes to rename. Bummer.

I'd start by looking here first. This site helped me, when I
was whipping together an MSDOS floppy.

It says "rename" is for files, and "move" is for directories,
whatever that means.

http://www.vfrazee.com/ms-dos/6.22/help/rename.htm

If that isn't it, I'd check to make sure the attempt to "rename",
isn't picking up a script or executable of the same name, from
somewhere in your execution path. Sometimes, when writing scripts,
you give absolute paths for the tools, to prevent surprises. Or,
you define the execution path, local to the script, so the script
doesn't "escape into the woods" :) Perhaps a built-in command has
priority over a path search, but I don't know enough about your
environment to say what might be the case. I'd just experiment
until I got the right results.

Paul
 
P

Paul

Todd said:
The expanded script look like

rename d:\MyBackup\backup1 d:\MyBackups\backup2

I am renaming to the same drive

I am renaming directories, not files. The directories are full
of stuff. Takes about 20 minutes to rename. Bummer.

<repost - first one didn't seem to go anywhere>

I'd start by looking here first. This site helped me, when I
was whipping together an MSDOS floppy.

It says "rename" is for files, and "move" is for directories,
whatever that means.

http://www.vfrazee.com/ms-dos/6.22/help/rename.htm

If that isn't it, I'd check to make sure the attempt to "rename",
isn't picking up a script or executable of the same name, from
somewhere in your execution path. Sometimes, when writing scripts,
you give absolute paths for the tools, to prevent surprises. Or,
you define the execution path, local to the script, so the script
doesn't "escape into the woods" :) Perhaps a built-in command has
priority over a path search, but I don't know enough about your
environment to say what might be the case. I'd just experiment
until I got the right results.

Paul
 
T

Todd

I'd start by looking here first. This site helped me, when I
was whipping together an MSDOS floppy.

It says "rename" is for files, and "move" is for directories,
whatever that means.

http://www.vfrazee.com/ms-dos/6.22/help/rename.htm

If that isn't it, I'd check to make sure the attempt to "rename",
isn't picking up a script or executable of the same name, from
somewhere in your execution path. Sometimes, when writing scripts,
you give absolute paths for the tools, to prevent surprises. Or,
you define the execution path, local to the script, so the script
doesn't "escape into the woods" :) Perhaps a built-in command has
priority over a path search, but I don't know enough about your
environment to say what might be the case. I'd just experiment
until I got the right results.

Paul

I think maybe I am barking up the wrong tree. I have an

attrib -h -s -r %BkPath%
attrib -h -s -r %BkPath%\*.* /S /D

That may be causing the long delays. I will have to check.

Thank you for the help!
-T
 
T

Todd

I'd start by looking here first. This site helped me, when I
was whipping together an MSDOS floppy.

It says "rename" is for files, and "move" is for directories,
whatever that means.

http://www.vfrazee.com/ms-dos/6.22/help/rename.htm

If that isn't it, I'd check to make sure the attempt to "rename",
isn't picking up a script or executable of the same name, from
somewhere in your execution path. Sometimes, when writing scripts,
you give absolute paths for the tools, to prevent surprises. Or,
you define the execution path, local to the script, so the script
doesn't "escape into the woods" :) Perhaps a built-in command has
priority over a path search, but I don't know enough about your
environment to say what might be the case. I'd just experiment
until I got the right results.

Paul

I think maybe I am barking up the wrong tree. I have an

attrib -h -s -r %BkPath%
attrib -h -s -r %BkPath%\*.* /S /D

That may be causing the long delays. I will have to check.

Thank you for the help!
-T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top