Solved

Adding condition to existsing DOS Script which adds file extension and replaces characters

Posted on 2007-03-22
7
188 Views
Last Modified: 2010-04-16
Hi,

In a dos batch script I use this command to rename files to use the extension of .xml

c:
cd c:\testing2
for %%a in (*.*) do ren %%a %%a.xml

I also use a second batch file to replace any . character with an _ character...

set source=c:\testing2
for /f "tokens=*" %%a in ('dir %source% /a-d /b') do call :process %%a
goto end


:process
set fname=%*
rename %source%\%fname% %fname:.=_%
:end

Would I need to do is two things...

1) Only add the .xml file extension if the file does not already have a .xml file extension

2) Incorporate both scripts together so its all one process

So the end result is hopefully a file with .xml as the file extension with only the . character before the xml file extension, any other would have been changed to _

Can anybody assist?

0
Comment
Question by:arundelr
[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
  • 5
  • 2
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18770340
Try this..

c:
cd c:\testing2
for %%a in (*.*) do if not %%~xa==.xml call :process %%dpnxsa
goto :eof

:process
ren %source%\%1 %fname:.=_%.xml
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18770348
type-o above..


c:
cd c:\testing2
for %%a in (*.*) do if not %%~xa==.xml call :process %%~dpnxsa
goto :eof

:process
ren %source%\%1 %fname:.=_%.xml
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18770369
Arg - yet again...  :|

cd /d c:\testing2
for %%a in (*.*) do if not %%~xa==.xml call :process %%~nxsa
goto :eof

:process
set fname=%1
ren %fname% %fname:.=_%.xml
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:arundelr
ID: 18770880
Hi Sirbounty,

I just tried this with a file caled 12345678.zzz which changed into 12345678_zzz.xml  - PERFECT

But then I tried with a file called 1234567991.zzz which is changed into 123456~1_ZZZ.xml

It appears not to handle the longer file names correctly, is there any work around here?
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18770897
Sure - simply strip out the short version (the 's' below) and use your original *..


cd /d c:\testing2
for %%a in (*.*) do if not %%~xa==.xml call :process %%~nxa
goto :eof

:process
set fname=%*
ren "%fname%" "%fname:.=_%.xml"
0
 

Author Comment

by:arundelr
ID: 18770943
Perfecto, thank you once again sirbounty ;o)))
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18770979
Happy to help! :^)
Thanx for the grade!!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

705 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