Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: Any 'For Loop' equilavent in VMS?

Original Message
Name: AugustineAndrew
Date: November 23, 2005 at 18:54:05 Pacific
Subject: Any 'For Loop' equilavent in VMS?
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!


Report Offensive Message For Removal

Response Number 1
Name: Joseph.Huber
Date: November 24, 2005 at 01:08:05 Pacific
Subject: Any 'For Loop' equilavent in VMS?
Reply: (edit)

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:



Report Offensive Follow Up For Removal

Response Number 2
Name: Joseph.Huber
Date: November 24, 2005 at 01:13:18 Pacific
Subject: Any 'For Loop' equilavent in VMS?
Reply: (edit)

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/


Report Offensive Follow Up For Removal

Response Number 3
Name: AugustineAndrew
Date: November 29, 2005 at 23:06:14 Pacific
Subject: Any 'For Loop' equilavent in VMS?
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 4
Name: AugustineAndrew
Date: November 29, 2005 at 23:21:29 Pacific
Subject: Any 'For Loop' equilavent in VMS?
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 5
Name: Joseph.Huber
Date: November 30, 2005 at 00:19:56 Pacific
Subject: Any 'For Loop' equilavent in VMS?
Reply: (edit)

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.


Report Offensive Follow Up For Removal

Response Number 6
Name: Joseph.Huber
Date: November 30, 2005 at 05:22:55 Pacific
Subject: Any 'For Loop' equilavent in VMS?
Reply: (edit)
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;"");}"



Report Offensive Follow Up For Removal

Response Number 7
Name: AugustineAndrew
Date: November 30, 2005 at 23:59:00 Pacific
Subject: Any 'For Loop' equilavent in VMS?
Reply: (edit)
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]


Report Offensive Follow Up For Removal

Response Number 8
Name: Joseph.Huber
Date: December 1, 2005 at 00:19:29 Pacific
Subject: Any 'For Loop' equilavent in VMS?
Reply: (edit)

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


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Any 'For Loop' equilavent in VMS?

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC