Solved

Batch file coding question

Posted on 2014-03-12
2
345 Views
Last Modified: 2014-03-12
Is there a way to edit the coding below so that when it changes all of the file names in the directory it can keep the - I am not sure what to change so that the - can be kept in the file name.

Any assistance offered would be appreciated.
@echo off
setlocal enabledelayedexpansion
set SourceFolder=C:\Temp\MyFiles
set SourceMask=00000-*.dwg
:Loop
echo Please enter the new prefix for all '%SourceMask%' files in %SourceFolder%.
set /p NewPrefix=Maximum of 10 characters, empty input cancels:
if "%NewPrefix%"=="" goto :eof
if not "%NewPrefix:~10,1%"=="" (
      echo Error: your input is longer than 10 characters!
      echo.
      goto Loop
)
for /f "delims=" %%a in ('dir /b "%SourceFolder%\%SourceMask%"') do (
      echo Processing %%a ...
      for /f "tokens=1* delims=-" %%n in ("%%a") do set NewName=%NewPrefix%%%o
      echo ... new name: !NewName!
      ECHO ren "%SourceFolder%\%%a" "!NewName!"
)
0
Comment
Question by:regsamp
2 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39924587
@echo off
setlocal enabledelayedexpansion
set SourceFolder=C:\Temp\MyFiles
set SourceMask=00000-*.dwg
:Loop
echo Please enter the new prefix for all '%SourceMask%' files in %SourceFolder%.
set /p NewPrefix=Maximum of 10 characters, empty input cancels: 
if "%NewPrefix%"=="" goto :eof
if not "%NewPrefix:~10,1%"=="" (
	echo Error: your input is longer than 10 characters!
	echo.
	goto Loop
)
for /f "delims=" %%a in ('dir /b "%SourceFolder%\%SourceMask%"') do (
	echo Processing %%a ...
	for /f "tokens=1* delims=-" %%n in ("%%a") do set NewName=%NewPrefix%-%%o
	echo ... new name: !NewName!
	ECHO ren "%SourceFolder%\%%a" "!NewName!"
)

Open in new window

0
 

Author Comment

by:regsamp
ID: 39924596
Perfect! Thank you so much for the extra help!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question