Page 1 of 1

Elementary file rename problem.

Posted: 22 May 2008 12:25
by r_fl_z
First the obvious: I don't know much about batch files.

I have searched long and hard for my own solution before imposing here, but have not been able to locate a solution.

I'm trying to create a simple routine to rename all of the files on a CDROM (or directory) by prepending a number to the beginning of each of the original file names.

example:
Assuming the number = 100
original file name = ORIGFILENAME.txt
rewritten file name = 100ORIGFILENAME.txt

Code: Select all

set n=100
echo %n%
xcopy e:\*.* D:\casephotos\%n%*.*


The code above produces the result below, which I have achieved by many different methods, which overwrites the first portion of the original file name with the text to be prepended instead of adding the text to the beginning.

original file name = ORIGFILENAME.txt
rewritten file name = 100GFILENAME.txt

Thanks in advance for your time.

r

Posted: 23 May 2008 11:41
by jeb
Hi,

I suppose you can't solve it with xcopy or copy,
but try this

Code: Select all

@echo off
setlocal

set srcPath=c:\temp\hund
set prefix=100
echo %prefix%

for %%a in (%srcPath%\*.*) do echo ren %%a %%~dpa%prefix%%%~nxa


jeb