.bat sintax

hi
i need to made a .bat file that do a rename if find a file, if dont, do the opositive thing
somthing like this
g:
cd proyectos
cd 1008
cd psds
cd isoextractor
cd config

if  exist pipo_tuberia.ini

ren pipo.ini pipo_electrico.ini
ren pipo_tuberia.ini pipo.ini
pause
ErnestoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

micropc1Commented:
.
0
David SpigelmanPresident / CEOCommented:
Let me make sure I understand what you're trying to do:

You're switching to the G: drive, and then changing to the g:\proyectos\1008\psds\isoextractor\config directory. Then you're looking for a file called pipo_tuberia.ini. If it exists, you want to rename pipo.ini as pipo_electrico.ini, and then rename pipo_tuberia.ini as pipo.ini. But if pipo_tuberia.ini doesn't exist, you want it to skip the whole thing. Right?

Batch file syntax isn't quite as structured as some others, like PowerShell or VBScript. To do what I think you're trying to do, you need to do something like this:

G:
cd proyectos\1008\psds\isoextractor\config

if exist pipo_tuberia.ini goto CHANGEFILES
goto END

:CHANGEFILES
ren pipo.ini pipo_electrico.ini
ren pipo_tuberia.ini pipo.ini

:END
pause
0
micropc1Commented:
Yeah, I posted something, but then i read it again and I was a little confused... by 'opositive thing' do you mean 'opposite thing'? something like...

g:
cd g:\proyectos\1008\psds\isoextractor\config

if not exist pipo_tuberia.ini goto notexist

ren pipo.ini pipo_electrico.ini
ren pipo_tuberia.ini pipo.ini

goto end

:notexist
ren pipo_electrico.ini pipo.ini 
ren pipo.ini pipo_tuberia.ini 

:end
pause

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

ErnestoAuthor Commented:
yes and if find pipo_electrico what to do?
i mean viceversa
i need if find pipo_electrico.ini convert it in pipo.ini

tsm
0
David SpigelmanPresident / CEOCommented:
Then do what micropc1 suggested. Same thing, he just added the code to switch them the other way - I didn't because I wasn't sure that's what you wanted to do.
0
micropc1Commented:
actually i think i had the second 'ren's backwards. I'm thinking it should be....

g:
cd g:\proyectos\1008\psds\isoextractor\config

if not exist pipo_tuberia.ini goto notexist

ren pipo.ini pipo_electrico.ini
ren pipo_tuberia.ini pipo.ini

goto end

:notexist
ren pipo.ini pipo_tuberia.ini 
ren pipo_electrico.ini pipo.ini 


:end
pause

Open in new window

0
David SpigelmanPresident / CEOCommented:
Yes. That looks correct.
0
Steve KnightIT ConsultancyCommented:
And you can simplify / complicate a little more with using some more of the batch syntax:

This will look for pip_tuberia.ini and if it exists then rename current pipo.ini to pipo.electrico.ini, then rename pip_tuberia. to pipo.ini

Otherwise it checks for pipo.electrico.ini and if THAT exists then it renames pipo.ini to pipo_tuberia.ini,  then renames pipo.electrico.ini to pipo.ini

Otherwise it just says "no rename done"

Steve

@ECHO OFF
CD /d G:\proyectos\1008\psds\isoextractor\config

IF EXIST pipo_tuberia.ini (
   RENAME pipo.ini pipo_electrico.ini
   RENAME pipo_tuberia.ini pipo.ini
   ECHO File pipo_tuberia.ini renamed
) ELSE (
   IF EXIST pipo_electrico.ini (
      RENAME pipo.ini pipo_tuberia.ini pipo.ini
      RENAME pipo_electrico.ini pipo.ini pipo_electrico.ini
      ECHO File pipo_electrico.ini renamed
    ) ELSE (
      ECHO Files NOT renamed as neither exists
    )
)
PAUSE

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Paul TomasiCommented:
This doesn't make a lot of sense at all.


Okay, am I reading this right...

    if pipo_tuberia.ini exists then
        rename pipo.ini to pipo_electrico.ini and,
        rename pipo_tuberia.ini to pipo.ini
    otherwise if pipo_tuberia.ini does NOT exist then
        what do we do here i.e, what do we rename to what?
    end-if
0
David SpigelmanPresident / CEOCommented:
Cool! I didn't realize you could do all that () stuff in a batch file. I tested that out and it works nicely.
0
Steve KnightIT ConsultancyCommented:
Paul - I assume he has two INI files which he swaps and renames to pipo.ini for an application that expects that file.

Could keep two copies and copy over the main one if they were fixed but if they are dynamically written to by the app. then best off renaming them back and forwards if the application doesn't allow a way of doing it differently I guess.

Steve
0
ErnestoAuthor Commented:
withc one you test??
please
0
ErnestoAuthor Commented:
oohh man
think you got it
so genious
let me test
0
David SpigelmanPresident / CEOCommented:
I think that all you're asking for, edo60, is what micropc1 put up there last. That'd work just fine. The others are providing solutions that are more elegant and flexible, and they're cool. They check for other things, provide for contingencies, etc. But you said that all you wanted was a script that would:

Check to see whether pipo_tuberia.ini exists
If it does, change pipo.ini to pipo_electrico.ini, and then change pipo_tuberia.ini to pipo.ini.
If it doesn't, change pipo.ini to pipo_tuberia.ini, and then pipo_electrico.ini to pipo.ini.

micropc1's script does that, and it's simple.
0
Paul TomasiCommented:
dragon-it

I leave it in your capable hands :)
0
Steve KnightIT ConsultancyCommented:
Mine has a copy/paste error on line 10/11 which should be:

RENAME pipo.ini pipo_tuberia.ini
RENAME pipo_electrico.ini pipo.ini

But as has been said is just a different layout of the logic already put my micropc1 so go with what you feel comfortable reading.
0
ErnestoAuthor Commented:
regards to all
tsm
0
Steve KnightIT ConsultancyCommented:
Thankyou, perhaps splitting the points would have been fairer with the work the others did first/
0
ErnestoAuthor Commented:
Oh man,
sorry!!
Im in a hurry and cant' think in about it, but for the next im going to take on caunt,
Thank you a lot
that code do exactly what im looking for
so genious
regards
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.