tags:

views:

51

answers:

2

I have a directory (source) with a bunch of files and these two dlls

file1.dll

file2.dll

I want to copy these to destination but on the copy have them renamed

file1_a.dll

file2_a.dll

Basically append _a to every dll copied

I need a very basic way to generate this script with a batch file Can't use perl because it's not built in to windows.

Is vbs my best option?

I tried good old

copy *.dll *64.dll

but that was a no go.

+4  A: 

Use the for command:

for %f in (t*.dll) do copy SourceDir\%f  DestDir\%~nf_a.dll

Remember to use a double % (%%) if used in a batch file.

Preet Sangha
+1  A: 

To add to Preet's answer, the following batch script renames all files that match a mask you pass in. You can either:

  1. Append a pattern to the end of the filename (file1.dll ==> file1_a.dll).
  2. Insert a pattern at the beginning of the filename (file1.dll ==> a_file1.dll).
  3. Replace the filename with a pattern and sequence number (file1.dll ==> mydll_1.dll; file2.dll ==> mydll_2.dll).

RenameAll.bat

@echo OFF

setlocal

@echo.
set /p PATTERN="Enter text pattern to add to file names: "
@echo %PATTERN%

:GETLOC
@echo.
@echo (A)ppend pattern to end of filename
@echo (I)nsert pattern at beggining of filename
@echo (R)eplace filename with pattern and sequence number
@echo ---------
@echo (Q)uit
@echo.
set /p LOCATION="Enter choice: "
@echo %LOCATION%

if /I '%LOCATION%' equ 'A' goto FILELOOP
if /I '%LOCATION%' equ 'I' goto FILELOOP
if /I '%LOCATION%' equ 'R' goto FILELOOP
if /I '%LOCATION%' equ 'Q' goto END
@echo Choice %LOCATION% invalid, try again.
goto :GETLOC

SET /A SEQ_NO=0

:FILELOOP
@echo Renaming file %1...
if %1.==. goto END
@echo %1
SET /A SEQ_NO=SEQ_NO+1
if /I '%LOCATION%' equ 'A' for %%i in (%1) do ren %%i "%%~ni%PATTERN%%%~xi"
if /I '%LOCATION%' equ 'I' for %%i in (%1) do ren %%i "%PATTERN%%%~ni%%~xi"
if /I '%LOCATION%' equ 'R' for %%i in (%1) do ren %%i "%PATTERN%%SEQ_NO%%%~xi"
SHIFT
goto FILELOOP

:END
@echo Rename batch complete.
::pause
endlocal

If you put a shortcut to this in you SendTo folder, you can select files in Windows Explorer, right-click, and pass them through the script to rename all in one go. With a little work you can get this to copy instead of rename (or both).

Patrick Cuff
sweet! I never think of putting things in send to...
Preet Sangha