- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Testing the size of a file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 06:45 AM
тАО02-01-2010 06:45 AM
How can I test the size of a file in a DCL script using IF/THEN/ELSE/ENDIF ?
I basically want to do this:
IF (size of file.txt) .GT. 0
THEN
do_this
ELSE
do_that
ENDIF
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 07:02 AM
тАО02-01-2010 07:02 AM
Re: Testing the size of a file
$ if f$file(FileNameInASymbol,"EOF") .gt. 0
$ then
$ write sys$output "Stuff"
$ else
$ write sys$output "No Stuff"
$ endif
Alternatively:
$ write sys$output "File size: " + f$file("SYS$LOGIN:LOGIN.COM","EOF")
13
$
Logical names and symbols will confuse you, as will the vast differences in the process model; you'll need to sort that out.
Lexical functions are the rough analog of some of the built-in stuff in the bash shell.
Here's some related mappings of shell and DCL commands:
http://labs.hoffmanlabs.com/node/741
As for recommended reading, see the OpenVMS User's Guide and the DCL dictionary in the OpenVMS documentation set:
http://www.hp.com/go/openvms/doc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 07:04 AM
тАО02-01-2010 07:04 AM
SolutionYou can use the lexical function F$FILE to get the size of the file:
F$FILE("file.txt","EOF")
gives you the number of blocks used in the file.
F$FILE("file.txt","FFB")
gives you the first free byte in the last block.
(F$FILE("file.txt","EOF") - 1) * 512 + F$FILE("file.txt","FFB")
gives you the file size in bytes.
Yours example will probably be something like this:
IF F$FILE("file.txt","EOF") .GT. 0
THEN
do_this
ELSE
do_that
ENDIF
Bojan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 07:16 AM
тАО02-01-2010 07:16 AM
Re: Testing the size of a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 07:17 AM
тАО02-01-2010 07:17 AM
Re: Testing the size of a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 03:12 PM
тАО02-01-2010 03:12 PM
Re: Testing the size of a file
A caveat on using F$FILE attribute EOF... if the file is currently open, and being written the EOF may not be up to date, so EOF could potentially be 0, even if you consider the file to contain data. For structured (indexed) files EOF doesn't mean much, so may not make sense.
Look at your candidate files, and compare different attributes to make sure you're getting results you want. As Bojan has suggested EOF and FFB are good for calculating the size of a sequential file, but you may be more interested in ALQ (allocated size). For example, a new file being written by another process may have EOF=0, but if any data has been written ALQ will be non-zero.
See
$ HELP LEX F$FILE ARG
for a list of file attributes you can test.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 07:10 PM
тАО02-01-2010 07:10 PM
Re: Testing the size of a file
(F$FILE("file.txt","EOF") - 1) * 512 + F$FILE("file.txt","FFB")
gives you the file size in bytes.
<<<
This only holds if the FFB is .NE.0 . For FFB.EQ.0, the size in bytes is F$FILE("file.txt","EOF") * 512 .
cu,
Martin