Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

renaming files help

 
SOLVED
Go to solution
ben_moore34
Advisor

renaming files help

Hello.

I'm after some help in renaming files on a VMS/ VAX system.

The files are called
Benbad.310;1
Benbad.311;1
Benbad.312;1
Benbad.314;1
.....and so on
There are about 300 or so files.
I want to rename them to
Benin.010;1
Benin.011;1
Benin.012;1
Benin.014;1
....and so on (relace the 3 to a 0)

I have tried rename Benbad.3*;1 to Benin.0*;1
but it comes up with 'error opening file Benin.0*; as output

Anyone know of a way of renaming the whole lot of files easily? I don't really want to rename each one one at a time as it'll take ages.

Many thanks in advance

BM
17 REPLIES 17
Jan van den Ende
Honored Contributor
Solution

Re: renaming files help

Ben,

to begin with:
WELCOME to the VMS forum!

For your problem, I would create a small DCL command file.

$loop:
$ next = f$search("benbad.*")
$ if next .eqs. "" then goto done
$ ext = f$parse(next,,,"extention") - "."
$ if f$type(ext) .nes. "INTEGER" then goto done
$ if ext .lt. 300 then goto done
$ nwext = ext - 300
$ rename 'next' *.'nwext
$ goto loop
$done:


Explanation:
-find the next file called benbad -- any extension
-get its extension, but remove the "."
-test it for being a number
-if it is less than 300 you may have restarted (check this for validity in your environment; might need to change to GOTO LOOP)
- subtract 100
- rename
- repeat

hth

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Robert Gezelter
Honored Contributor

Re: renaming files help

Ben,

I would write a small DCL script to iterate through the directories using F$SEARCH, then F$PARSE to break the resulting filenames into their component pieces, then constructing the desired filename. Finally use the RENAME command to actually rename from the old file to the new file.

You may find my presentation on DCL Lexical functions from the Fall 1995 DECUS Symposium useful (the PDF of the slides can be found at http://www.rlgsc.com/decus/usf95/index.html ).

- Bob Gezelter, http://www.rlgsc.com
ben_moore34
Advisor

Re: renaming files help

Hello Jan

Many thanks for the quick reply. I'll give this a go and let you know how I get on.

Cheers

Ben
ben_moore34
Advisor

Re: renaming files help

Thanks Rob

I'll take a look at that.

Cheers guys

Ben
Hein van den Heuvel
Honored Contributor

Re: renaming files help

Well, there is no direct RENAME option to do this.

You can go the DCL route with an F$SEARCH in a loop, pick apart the filename (f$PARSE) and rename or... use PERL.

$! dir be*
Benbad.310;1 Benbad.311;1 Benbad.312;1 Benbad.314;1

$ ! Always do a dry-run:
$ perl -e "for () {$o = $_; s/\.3/.0/; print qq($o $_\n)}"
benbad.310 benbad.010
benbad.311 benbad.011
benbad.312 benbad.012
benbad.314 benbad.014

$ ! Now for real...

$ perl -e "for () {$o = $_; s/\.3/.0/; rename $o,$_ }"

$ dir be*
benbad.010;1 benbad.011;1 benbad.012;1 benbad.014;1

Hein.





Hein van den Heuvel
Honored Contributor

Re: renaming files help

btw...
For me this is one of the most use perl 'one-liner' in my personal repetoir :-).

For those who are not too familiar with perl but intersted some, here is that command in slow motion:

perl -e ! Command to follw in string
for () ! Loop over some array returning
! elements into default variable $_
! GLOB function returing arrya of matching file names
{ ! Block open
$o = $_; ! copy $_ into $o (old name)
s/\.3/.0/; ! Substitute .3 with a .0
! Escape the period as it is a wildcard.
rename $o,$_ ! Function to do the deed
} ! Block Done, loop around

Hein.




ben_moore34
Advisor

Re: renaming files help

Hello

I think I'm going to have to use the DCL script method here as PERL is not installed on our VAX.

You are going to have to forgive me a bit here as I am pretty new to VMS and programming. I'm understanding the general idea of how the f$search & parse are operating.

I have created the DCL script and called it rename.com. Whenever I try to run it I'm getting

@rename
%DCL-W-IVKEYW, unrecognized keyword - check validity and spelling
\EXTENSION\

I'm obviously doing something basic wrong here.

Thanks

Ben
Hein van den Heuvel
Honored Contributor

Re: renaming files help


Ben,

Check out: $help lexi f$parse arg

Jan wrote: $ ext = f$parse(next,,,"extention") - "."
Jan meant: $ ext = f$parse(next,,,"TYPE") - "."

Jan's solution uses integer calculation.
Thje description of your problem suggested STRING manipulation to me.

Suggested code ('works for me' :-)

$loop:
$ next = f$search("benbad.*")
$ if next .eqs. "" then goto done
$ ext = f$parse(next,,,"TYPE") - ".3"
$ rename/log 'next' .0'ext
$ goto loop
$done:

Hein.
Jan van den Ende
Honored Contributor

Re: renaming files help

Ben,

Hein (Hi Hein, still sorry for missing our bridge appointment because of medical reasons last year, all the more since bootcamp for 2009 is cancelled!) is right of course.
My bad, I did not check the docs.

As for Hein's variant:

- ANY extension starting with the digit 3 would also be done, such as .3ABC, any in the 30's, any 3000's, any 30000's.

- my solution will also rename 4nn to 1nn, 5nn to 2nn, etc.
Check which is relevant to you!!

hth

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
ben_moore34
Advisor

Re: renaming files help

Thanks for that

I'm getting somewhere with this now
The BENIN files are now showing as
BENIN.10
BENIN.11
BENIN.12
BENIN.14

That was using

$loop:
$ next = f$search("benin.*")
$ if next .eqs. "" then goto done
$ ext = f$parse(next,,,"type") - "."
$ if f$type(ext) .nes. "INTEGER" then goto done
$ if ext .lt. 300 then goto done
$ nwext = ext - 300
$ rename 'next' *.'nwext'
$ goto loop
$done:

Unfortunately for the program to process these files they need the .0 before the extention
ie
BENIN.010
BENIN.011

I think I'm going to have to do a bit of research into this tonight.


Robert Gezelter
Honored Contributor

Re: renaming files help

Ben,

Ok, with all due respect to Jan and Hein, this is why I try not to post code more than a line or so in length.

It is VERY dangerous to run code WITHOUT knowing precisely how it functions. It is easy to run something using CUT/PASTE that can cost dearly (I do presume that the directory was backed up BEFORE running this procedure).

The line:

nwext = ext - 300

Will subtract 300 from the number. The default for numeric->string conversion in DCL is the minimum number of digits.

In this instant case of all the numbers being between 300 and 399 inclusive, the problem can be corrected by changing the RENAME command:

$ rename 'next' *.'nwext

to

$ rename 'next' *.0'nwext

For a more general fix, one will need to look up the F$FAO lexical function and use the formatting options to reformat the name in whatever format is desired (e.g., hex, octal, decimal). One can also do other transformations as needed, if one wants to be more creative.

- Bob Gezelter, http://www.rlgsc.com
ben_moore34
Advisor

Re: renaming files help

Thankyou everyone for your help.
I really have learned a lot tonight
My problem has now been solved thanks to the help from all of you.

All files are now ready for processing (I did experiment on some test files that I created earlier)

I owe you all a pint.

When time allows I must learn some more DCL.
Incidenatally what kind of systems are you guys using?
We have a load of VAX 4000 machines

Bye for now
BM
Robert Gezelter
Honored Contributor

Re: renaming files help

Ben,

Glad to be of assistance!

VAX 4000 systems are one of the later generations of VAX systems.

In my lab, my systems range from MicroVAX II systems up through Alpha to Itanium.

Since DCL is the native scripting and command language, it is very useful. The best information is in the documentation set. Recent versions are available under "Documentation" at http://www.hp.com/go/openvms

While some details of DCL have been extended since the last VAX release, the language as a whole has been completely stable for a LONG time.

- Bob Gezelter, http://www.rlgsc.com
Jan van den Ende
Honored Contributor

Re: renaming files help

Ben,

>>>
I owe you all a pint.
<<<

Thank you very much. At the time you wrote that, I was having a Grimbergen Triple. For those who do not know: the Monastry of the Belgian village Grimbergen founded a brewery in 1128 (yes, nearly 900 years ago!)
The Triple is a high-fermenting yellow beer with a lot of body ("Stammwuerze") and 9% EtOH.

But on expressing your thanks in the Forum, please review

http://forums1.itrc.hp.com/service/forums/helptips.do?#33

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Jan van den Ende
Honored Contributor

Re: renaming files help

Ah, one more

>>>
Incidenatally what kind of systems are you guys using?
<<<

I have 2 Alpha 1000 systems at home. (plus 2 Vax 3100, but those have not seen any electricity since I moved in 2001, so they probably don't count)

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Hein van den Heuvel
Honored Contributor

Re: renaming files help

Ben>> owe you all a pint.
Jan> Thank you very much. At the time you wrote that, I was having a Grimbergen Triple

And I was enjoying a Shipyard seasonal (Prelude). I had a Grimbergen earlier this month.. in Eindhoven. Not my favourite, but I keep trying. Maybe some day.
For abbey beers I stick to the 'dubbel' (La Trappe). Martha's Exchange here in Nashua has a reasonable version of it on draft right now.

Ben>> Incidenatally what kind of systems are you guys using?

I 'tested' your request on my RX2620 Itanium.
In my lab I have a VaxStation 4000/60(?), 2xDS10, rx2620, rx2600, msa1000+14drives, 16/2 fibreswitch, 24xGigabit network, Decserver90m, BA356, DS2100, DL380, Linux ThinClient as 'terminal' for consoles/webbrowsing. Ebay!

Hein.


ben_moore34
Advisor

Re: renaming files help

Thanks.

I was having a bottle of Adnams Broadside (Suffolk Ale)when the file renames had completed.

I'm familiar with Grimbergen beers, they can be found from time to time in shops & bars here (have only tried the one with the yellow label). I really like those Abbey beers. I want to try them all.

Cheers Guys