Link to home
Start Free TrialLog in
Avatar of Prashanth_atthaluri
Prashanth_atthaluri

asked on

Renaming extensions of files in DOS

Hi

I am using XP professional.

i have a folder, with following files
c:\Source\STMTPRNT.SPL.Extracted900-026-61122007
                STMTPRNT.SPL.Extracted900-027-41122007
                STMTPRNT.SPL.Extracted900-028-21122007
                STMTPRNT.SPL.Extracted900-030-81122007
                STMTPRNT.SPL.Extracted900-031-61122007
i want to move them to another folder
c:\Destination\STMTPRNT.SPL.Extracted900-026-61122007.txt
                STMTPRNT.SPL.Extracted900-027-41122007.txt
                STMTPRNT.SPL.Extracted900-028-21122007.txt
                STMTPRNT.SPL.Extracted900-030-81122007.txt
                STMTPRNT.SPL.Extracted900-031-61122007.txt

i am using the following command

xcopy c:\source\*.extracted*  c:\destination\*.extracted*.txt /s

but in the destination only one file is created as
c:\Destination\STMTPRNT.SPL.txt

Please, help me. I am new to DOS, detailed explanation is highly appriciated.

Thanks
                 
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Try:

xcopy c:\source\*.extracted*  c:\destination\*.txt /s

HI,

MSDOS will only read and create files with the 8.3 file format

 xxxxxxxx.xxx (8.3)

For more detail have a look at this article

http://en.wikipedia.org/wiki/8.3_filename

Regards,
TT
Avatar of Prashanth_atthaluri
Prashanth_atthaluri

ASKER

Hey paul

i tried the command you mentioned, its creating only one file, which means all the previous files are  replaced.

Thanks
I would recommend trying something like this instead:


for /f %i in ('dir /a-d /b c:\source\*extracted*) do ('xcopy c:\source\%i c:\destination\%i.txt /s')


Hope this helps!

:o)

Bartender_1
xcopy /s/c/h/d "source"\*.* "destination"\*.*
Sorry, second set of quotes is not necessary, this command from the command line should work:

for /f %i in ('dir /a-d /b c:\source\*extracted*) do (xcopy c:\source\%i c:\destination\%i.txt /s)

If you want to use this command in a batch file it should look like this:


for /f %%i in ('dir /a-d /b c:\source\*extracted*) do (
xcopy c:\source\%i c:\destination\%i.txt /s
)


Hope this helps!

:o)

Bartender_1
~sighs~ nothing like using copy/paste to replicate errors....

Sorry, try this command from the command line:

for /f %i in ('dir /a-d /b c:\source\*extracted*') do (xcopy c:\source\%i c:\destination\%i.txt /s)

this for a batch file:

for /f %%i in ('dir /a-d /b c:\source\*extracted*') do (
xcopy c:\source\%i c:\destination\%i.txt /s
)
hey Bartender_1

I have used
for /f %%i in (dir /a-d /b C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\*extracted*) do (xcopy C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\%i C:\FDIC\VisionBKP\Data\visiontxt\%i.txt /s)

i got the following error:

%%i was unexpected at this time.

Thanks
If this is from the command line, try this:

for /f %i in ('dir /a-d /b C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\*extracted*') do (xcopy C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\%i C:\FDIC\VisionBKP\Data\visiontxt\%i.txt /s)
If used from the command line, the variable is denoted with a single %, if used in a batch file, it needs a double %%.
Also, please note, that in either case you need to use a single quote around the command 'dir /a-d /b c:\path\*extracted*'

Hope this helps!

:o)

Bartender_1
You are better off doing the copy/move part first, and then rename files - that is much easier to accomplish, and faster.

pushd c:\FDIC\VisionBKP\Data
xcopy ARCHIVE_unzipped\*extracted* visiontxt\
ren visiontxt\*extracted*. *extracted*.txt
popd


Bartender,

There is no use of FOR /F in that case (and the parens around the xcopy are superfluous). It works, but it is cumbersome. A simple
for %i in (c:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\*extracted*) do xcopy "%i" "C:\FDIC\VisionBKP\Data\visiontxt\%~nxi.txt"
is much better. Further, the /s for xcopy is even wrong - we do not want to go into subfolders.
Qlemo,

~sheepish grin~ You're right of course. I didn't even bother to check the switches for the xcopy command.
Hey Bartender

  Sorry for misleading example, there are many subfolders from which i have to copy the files.

when i run this cmd
for /f %i in ('dir /a-d /b C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\*extracted*') do (xcopy C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\%i C:\FDIC\VisionBKP\Data\visiontxt\%i.txt /s)

I think there is a problem, i.e when ever there is a space in folder name eg:
C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\vision-20091116140126 [289]_rebuild\
then the variable is just returning C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\vision-20091116140126

so i am getting, the following error
C:\FDIC\VisionBKP\Data\visiontxt\STATEMENTS>ren "c:\FDIC\VisionBKP\Data\visiontxt\STATEMENTS\vision-20101217235906" "i.txt"
The system cannot find the file specified.

Please, let me know the solution.

Thanks



Ok,

Just to ensure I have a clear picture here, you have a number of files, in multiple subfolders, some containing spaces in the names, all within the "C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped" folder, and you want to copy all of the files to a backup location and append the ".txt" to the filenames. Am I correct in assuming you wish to retain the folder structure in the backup location?

Yes Sir.
Ok, Are you attempting to do this in a single command you can enter from the command line, or can this be put into a batch file?

I don't know of any way with simple commands to do this all in one go. Qlemo is correct, at this point it is simpler to copy the files over, then do the renaming.

Strictly speaking, you could enter multiple commands on the command line and accomplish this, but that's what a batch file is supposed to be for, to take multiple lines of commands, and execute them in sequence.

Please, give me the batchfile.

i tried what 'Qlemo' said. Copied first and tried to rename later. But did not kow how to use 'REN' to rename files in subfolders.

Thanks
SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, in your batch file you'll want this:



@echo off
xcopy "C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\*extracted*" C:\FDIC\VisionBKP\Data\visiontxt\ /s
for /f "delims=" %%i in ('dir /a-d /b /s C:\FDIC\VisionBKP\Data\visiontxt\') do ren "%i" "%~ni.txt"

Open in new window

Wups. Guess I'm slow.

:o)

Bartender_1
Ehem. You forgot to use %% instead of % in your rename command ;-).
You're correct of course.

:o)

Bartender_1
@echo off
xcopy "C:\FDIC\VisionBKP\Data\ARCHIVE_unzipped\*extracted*" C:\FDIC\VisionBKP\Data\visiontxt\ /s
for /f "delims=" %%i in ('dir /a-d /b /s C:\FDIC\VisionBKP\Data\visiontxt\') do ren "%%i" "%%~ni.txt"

Open in new window

Hey Bartender

when i ran this cmd

for /f "delims=" %i in ('dir /a-d /b /s C:\FDIC\Westbridge\VisionBKP\Data\visiontxt\Statements') do ren "%i" "%~ni.txt"

i got following error

ren "C:\FDIC\Westbridge\VisionBKP\Data\visiontxt\Statements\vision-20101217235906 [289]\STMTSAVG.spl.Extracted500-100-312172010" "STMTSAVG.spl.txt"
A duplicate file name exists, or the file cannot be found.

I think .extracted* part is getting replaced by .txt. Please, look into it.
I appriciate the pain you are taking to help me.

Thanks a lot.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey, Bartender Thanks so much.
Thanks Qlemo