hello guys,
I have a problem and I hope you can solve it for me
I have I file that is located here:
C:\Oracle\product\11.2.0\client_1\network\admin\tnsnames.ora
I want to rename it by batch and copy a new one in the same folder.
My batch ist looking like this
@echo on
rename "C:\Oracle\product\11.2.0\client_1\network\admin\tnsnames.ora" "C:\Oracle\product\11.2.0\client_1\network\admin\tnsnames_old.ora"
copy tnsnames.ora C:\Oracle\product\11.2.0\client_1\network\admin\tnsnames.ora
pause
But the rename don't work... I always get a syntax error...
Need some help pls.
Greets sL0w
Batch to rename and copy a new file
Moderator: DosItHelp
Re: Batch to rename and copy a new file
Try this:
EDITED: to use Move instead of rename
EDITED: to use Move instead of rename
Code: Select all
@echo on
move /y "C:\Oracle\product\11.2.0\client_1\network\admin\tnsnames.ora" "C:\Oracle\product\11.2.0\client_1\network\admin\tnsnames_old.ora"
copy /b "tnsnames.ora" "C:\Oracle\product\11.2.0\client_1\network\admin"
pause
Re: Batch to rename and copy a new file
I tend to use a backup folder personally. But the same method works for renaming the file. Here's what I personally use.
Edited to fix quotation misplacement, set better flag, & explain a little bit.
Also, if you aren't using a backup folder "COPY" would work better than "XCOPY".
To use a folder instead just add that to the backup path in variable.
Alternatively you can do without the variables & just use the paths directly. I tend to be a little variable crazy. Parameters have a tendency of being used often & are subject to change. I found a variable to be the easiest way to deal with that.
Edited to fix quotation misplacement, set better flag, & explain a little bit.
Code: Select all
@ECHO OFF
SET "backup=C:\Oracle\product\11.2.0\client_1\network\admin\tnsnames_old.ora"
SET "original=C:\Oracle\product\11.2.0\client_1\network\admin\tnsnames.ora"
SET "new=C:\Downloads\tnsnames.ora" or where ever you may have it
REM setting flag /Y with XCOPY will overwrite existing file without prompt
@ECHO ON
XCOPY /Y %original% %backup%
XCOPY /Y %new% %original%
REM if you want the new file removed after copying use the following
DEL %new%
@PAUSE
Also, if you aren't using a backup folder "COPY" would work better than "XCOPY".
To use a folder instead just add that to the backup path in variable.
Code: Select all
SET "backup=C:\path~\Backup\tnsnames.ora"
Alternatively you can do without the variables & just use the paths directly. I tend to be a little variable crazy. Parameters have a tendency of being used often & are subject to change. I found a variable to be the easiest way to deal with that.