Renaming directories in DOS.
bud35000
Posted messages
155
Status
Member
-
Gordon -
Gordon -
Bonjour,
I would like to rename a whole series of directories by changing the extension.
I created a batch for that.
My problem is that with this batch I can add an extension but not replace the existing one.
Here is my script:
this one adds the extension I want:
rem for /F %%i in ('dir/B') DO RENAME %%i %%i.txt
but to remove the extension that existed before, I tried the following script but it does not work:
FOR /F %%i in ('dir/B') DO (ECHO %%i) | FOR /F "tokens=1 delims=." %%j in ('findstr "<.doc"') DO RENAME %%i %%j.txt
Moreover, I was inspired by scripts found on the net but I do not see what "tokens" and "delims" are for...
Could we get some help?
I would like to rename a whole series of directories by changing the extension.
I created a batch for that.
My problem is that with this batch I can add an extension but not replace the existing one.
Here is my script:
this one adds the extension I want:
rem for /F %%i in ('dir/B') DO RENAME %%i %%i.txt
but to remove the extension that existed before, I tried the following script but it does not work:
FOR /F %%i in ('dir/B') DO (ECHO %%i) | FOR /F "tokens=1 delims=." %%j in ('findstr "<.doc"') DO RENAME %%i %%j.txt
Moreover, I was inspired by scripts found on the net but I do not see what "tokens" and "delims" are for...
Could we get some help?
Configuration: Windows 2000 Internet Explorer 6.0
6 answers
-
Hello,
is it to change .doc to .txt?
It seems to me that:rename .doc .txt *.doc
should work (well it works under linux...)
--
Tøƒ -
Ah, I'll need to change my OS then. It doesn't work under DOS.
-
Indeed, it works well like this with the files.
But it's not exactly what I want to do; actually, it's directories that I would like to rename, but it's my fault, I should have specified. -
Yes, these are folders that need to be automatically retrieved by an FTP. However, they are only processed by the batch script if they have a specific extension. I used .doc or .txt just as an example, but actually, they have other extensions specific to our software packages.
What’s strange is that the following script works. But I don't see how to remove the initial extension.
It’s easy with files, but with folders, the command line doesn’t seem to recognize the ""*.*"".
for /F %%i in ('dir/B') DO RENAME %%i %%i.dem
Thanks anyway for your help. -
For directories or files, the exact syntax is:
c:\test> for /F %i in ('dir/B') DO RENAME %i %i.txt
you must be in the directory containing the files and directories to rename.
you can change the txt extension to something else, for example Gadget.
a+ -
MOVE
Move files and rename files and directories.
To move one or more files:
MOVE | /-Y [drive:][path]file1[,...] destination
To rename a directory:
MOVE | /-Y [drive:][path]dir1 dir2
[drive:][path]file1 Specifies the location and name of the file(s) you want to move.
destination Specifies the new location of the file.
Destination can be a drive letter followed by
a colon (:), a directory name, or a combination. If you are moving a single file,
you can also include a filename if you want to rename the file while moving it.
[drive:][path]dir1 Specifies the directory you want to rename.
dir2 Specifies the new name of the directory.
/Y Suppresses confirmation prompt for
replacing existing destination files.
/-Y Causes confirmation prompt for
replacing existing destination files.
The /Y option may be present in the COPYCMD environment variable.
Override this by using /-Y in the command line. By default, a
confirmation prompt appears unless the MOVE command is executed from
a command script.