Ernesto
asked on
.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
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
.
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\iso extractor\ 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\isoext ractor\con fig
if exist pipo_tuberia.ini goto CHANGEFILES
goto END
:CHANGEFILES
ren pipo.ini pipo_electrico.ini
ren pipo_tuberia.ini pipo.ini
:END
pause
You're switching to the G: drive, and then changing to the g:\proyectos\1008\psds\iso
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\isoext
if exist pipo_tuberia.ini goto CHANGEFILES
goto END
:CHANGEFILES
ren pipo.ini pipo_electrico.ini
ren pipo_tuberia.ini pipo.ini
:END
pause
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
ASKER
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
i mean viceversa
i need if find pipo_electrico.ini convert it in pipo.ini
tsm
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.
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
Yes. That looks correct.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Cool! I didn't realize you could do all that () stuff in a batch file. I tested that out and it works nicely.
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
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
ASKER
withc one you test??
please
please
ASKER
oohh man
think you got it
so genious
let me test
think you got it
so genious
let me test
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:
micropc1's script does that, and it's simple.
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.
dragon-it
I leave it in your capable hands :)
I leave it in your capable hands :)
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.
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.
ASKER
regards to all
tsm
tsm
Thankyou, perhaps splitting the points would have been fairer with the work the others did first/
ASKER
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
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