Elementary file rename problem.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
r_fl_z
Posts: 1
Joined: 22 May 2008 12:02

Elementary file rename problem.

#1 Post by r_fl_z » 22 May 2008 12:25

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

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

#2 Post by jeb » 23 May 2008 11:41

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

Post Reply