Computing.Net > Forums > OpenVMS > Any 'For Loop' equilavent in VMS?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Any 'For Loop' equilavent in VMS?

Reply to Message Icon

Name: AugustineAndrew
Date: November 23, 2005 at 18:54:05 Pacific
OS: VMS Version V5.5-2
Comment:

Will any VMSguru or anyone help me out with this?

I'm trying to delete files in a directory based on a directory file listing of another different directory.

In Unix, i would perform the following:

foreach file (`ls <dir1>)
del <dir2>/$file
end

Is there an equivalent command of such in VMS? Or are there other ways to perform this operation?

Please kindly advice. Thanks a million!



Sponsored Link
Ads by Google

Response Number 1
Name: Joseph.Huber
Date: November 24, 2005 at 01:08:05 Pacific
Reply:


There are several implementations of such loops floating around. Have a look in http://dcl.openvms.org for each.com .

I You don't find, use the one on my server at
http://wwwvms.mppmu.mpg.de/util_root/com/each.com

I didn't write it, but use it frequently.

The syntax of your above loop would be:

each <dir1>*.* "delete <dir2>'nt';"

assuming the definition of each :== @dev:[dir]each or each.com being in DCL$PATH:



0

Response Number 2
Name: Joseph.Huber
Date: November 24, 2005 at 01:13:18 Pacific
Reply:


For the particular case of "delete a file if one with the same name exists in a different directory", there is my delete_if_exists.com, and delete_if_identical.com in

http://wwwvms.mppmu.mpg.de/util_root/com/


0

Response Number 3
Name: AugustineAndrew
Date: November 29, 2005 at 23:06:14 Pacific
Reply:

Hi Joseph,

Thanks for your suggestion.
But can i have an easier and non-complicated way to perform the loop?
How can i use the For loop to perform my work in VMS?

Can i work similarly to the way i used in UNIX?

foreach file (`ls <dir1>`)
del <dir2>/$file
end

On the other hand, how do i truncate the version number of a file when i output the directory listing of a directory?
For example:
abc.log;1
|
V
abc.log


0

Response Number 4
Name: AugustineAndrew
Date: November 29, 2005 at 23:21:29 Pacific
Reply:

Hi Joseph,

For better understanding, i'm trying to perform the following which i did successfully in UNIX.

I'm trying to capture the list of files in a particular directory and delete them in a connected machine.

For example in UNIX, i performed the following:

foreach file (`ls <dir1>`)
mem del $file
end

However, UNIX do not consist of any version number at the end of a filename. Hence, i would need to truncate the version number off the filename when i dir the files.


0

Response Number 5
Name: Joseph.Huber
Date: November 30, 2005 at 00:19:56 Pacific
Reply:


Since DCL has no loop construct like foreach, the mentioned each.com comes nearest.
But of course You can write a much simples procedure to perform the particular task:
To delete a file You HAVE to specify it's version number (or use a wildcard ";*" version to delete all. The DCL loop would be something like that:

$ pattern = "[dir1]*.*"
$loop:
$ file=f$search(pattern)
$ if file.eqs."" then goto done
$ delete 'file'
$ goto loop
$done:
$ exit

If You want to extract only parts of the file specification, use the f$parse lexical function like this:

$ fnode = f$parse(file,,,"NODE")
$ fdev = f$parse(file,,,"DEVICE")
$ fdir = f$parse(file,,,"DIRECTORY")
$ name = f$parse(file,,,"NAME")
$ ftyp = f$parse(file,,,""TYPE")
$ ver = f$parse(file,,,:VERSION")
$ nt = name+ftyp !file name.typ

Then e.g. delete all files with that name.typ:

$ delete 'nt';*

I don't understand what Your "mem del $file" in fact should do. If it means "delete file having this name" then the above delete does it.

And my delete_if_exists.com does it also.


0

Related Posts

See More



Response Number 6
Name: Joseph.Huber
Date: November 30, 2005 at 05:22:55 Pacific
Reply:

And BTW with a Unix-compatible "ls" command (e.g. from the HP sites GNV tool), and perl installed, the following one liner will do what You want:

perl -e "foreach my $file (`ls /disk/dir`) {chop($file);system(""delete $file;"");}"



0

Response Number 7
Name: AugustineAndrew
Date: November 30, 2005 at 23:59:00 Pacific
Reply:

Hi Joseph!
I've got it! You've been a great help! Thanks a million!

As for the DCL loop, how do i delete the same files from the f$search in a different directory when the f$search results include the full path of the files?
E.g.
f$search dir:
sys$sysdevice:[user.andrew.ABC]
Delete in dir:
sys$sysdevice:[user.andrew.CBA]


0

Response Number 8
Name: Joseph.Huber
Date: December 1, 2005 at 00:19:29 Pacific
Reply:


Simply parse the file-specification as shown earlier into name and type, variable nt, then

DELETE sys$sysdevice:[user.andrew.CBA]'nt';*

(the * only to delete eventually all versions, leave it off to delete only the newest).


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Any 'For Loop' equilavent in VMS?

VMS and Version Control www.computing.net/answers/openvms/vms-and-version-control/282.html

Search command in Vi for VMS www.computing.net/answers/openvms/search-command-in-vi-for-vms/517.html

errorhandling in VMS files www.computing.net/answers/openvms/errorhandling-in-vms-files/298.html