[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Batch file coding question

Posted on 2014-03-12
2
Medium Priority
?
353 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 85

Accepted Solution

by:
oBdA earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

834 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