Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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
endIs there an equivalent command of such in VMS? Or are there other ways to perform this operation?
Please kindly advice. Thanks a million!

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.comI 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:

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 inhttp://wwwvms.mppmu.mpg.de/util_root/com/

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
endOn 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

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
endHowever, 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.

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:
$ exitIf 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.typThen 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.

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;"");}"

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]

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).

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |