Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Renaming a filename

Posted on 2012-12-22
9
Medium Priority
?
395 Views
Last Modified: 2012-12-27
I have a program that generates bunch of files automatically. i don't have control on the base program. I need to be able to change the names of the files. Here is a sample.

tblEmployee.cs -> Employeedto.cs
tblDept.cs -> Deptdto.cs

I need to remove 'tbl' from the prefix and add 'dto' as the suffix before the file extension.

can someone please provide me the code for this renaming in MS DOC batch file?


Thanks a bunch,
Chandra
0
Comment
Question by:comtec100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
9 Comments
 
LVL 58

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 38716455
Give this a try.

@echo off
Set local enabledelayedexpansion
Pushd c:\yourdir
For %%A in (tbl*.cs) do (
  Set Name=%%~nA
  Ren "%%~A" "!Name:~3!dto.cs"
)
Popd

Open in new window

~bp
0
 

Author Comment

by:comtec100
ID: 38716535
Script:
@echo off
Set local enabledelayedexpansion
Pushd c:\Users\Chandra\temp
  For %%A in (tbl*.cs) do (
  Set Name=%%~nA
  Ren "%%~A" "!Name:~3!dto.cs"
)
Popd


Result:
C:\Users\Chandra\temp>changename.bat
LOCALAPPDATA=C:\Users\Chandra\AppData\Local
A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.

Can you please help?
0
 

Author Comment

by:comtec100
ID: 38716962
I've requested that this question be closed as follows:

Accepted answer: 0 points for comtec100's comment #a38716535

for the following reason:

script didn't quite work, but gave the framework. Thank you
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 38716683
The script would work as is IMO except there is a spurious space on the set local line.  Changed to just setlocal it should be fine.

Steve
0
 
LVL 58

Expert Comment

by:Bill Prew
ID: 38716956
Sorry for the extra space in setlocal, worked this question on a mobile device and it was nice enough to put in that space on its own, argh.

~bp
0
 
LVL 58

Expert Comment

by:Bill Prew
ID: 38716963
Given the posters final comment, shouldn't http:#a38716455 be accepted as the solution or at least a points scoring assist, in which case the poster should post their modified working version.

~bp
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38717663
Agreed give Bill the points, was only a space added!

My mobile seems to auto-complete words really annoyingly and doesn't seem to allow turning it off in a browser text box, you hit a space after a word in a piece of code and it helpfully adds the last bit of text you had after that combination etc.  Must delve a bit for the "off" button on that I suppose!

Steve
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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