Reputation: 1979
I have list of the file which their extension are different, I want to know how by using batchfile I can do below modification?
BPG_ANNUITY .pkb --- should rename to ----> PACKAGE BODY BPG_ANNUIT Y .sql BPG_ANNUITY .pks --- should rename to ----> PACKAGE BPG_ANNUITY .sql
I tried to rename the files by below comment but it was not working.
ren *.pks "PACKAGE *.sql"
ren *.pkb "PACKAGE body *.sql"
I received below error:
A duplicate file name exists, or the file cannot be found.
would you mind help me? I am using windows 7,64bit.
Upvotes: 1
Views: 490
Reputation: 130919
You can use regular expressions to conveniently rename your files via my JREN.BAT utility - a hybrid JScript/batch script that runs natively on any Windows machine from XP onward.
call jren "(.*\.)pks$" "PACKAGE $1sql"
call jren "(.*\.)pkb$" "PACKAGE BODY $1sql"
Upvotes: 0
Reputation: 14345
You can't use wildcards to rename files like that. You can, however, process a list of files and rename them one by one.
for /f %%A in ('dir /b *.pks') do ren %%A "PACKAGE %%~nA.sql"
for /f %%A in ('dir /b *.pkb') do ren %%A "PACKAGE BODY %%~nA.sql"
The first command will get a list of the names of all .pks files in the present directory (the /b
option returns only the file name). The ~n
portion of %%~nA will return the file name without the extension - in your example, BPG_ANNUITY with no extension. The ren
command then takes the old file name and changes it to PACKAGE BPG_ANNUITY.sql
and continues with the rest of the .pks files in the directory.
The second command works the same way, but with .pkb files.
Upvotes: 1