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

To delete a file if the sie of the file is less than 1 blocks in OpenVms

 
SOLVED
Go to solution
Highlighted

To delete a file if the sie of the file is less than 1 blocks in OpenVms

Hi Al,

I need to delete files which get created with 0 blocks. please help me.
i need a command to delete files which are less than 1 block in VMS.
15 REPLIES 15
Highlighted
Valued Contributor

Re: To delete a file if the sie of the file is less than 1 blocks in OpenVms

Hi!

This will generate a list of zero block files:

$direct/sel=size=max=1/col=1/nohead/notrail

You can then open up this file, read each record in and issue a $DELETE command.

HTH

Craig
Highlighted
Valued Contributor

Re: To delete a file if the sie of the file is less than 1 blocks in OpenVms

Whoops!

And you also need:

/size=all on the $direct command line.

Craig
Highlighted

Re: To delete a file if the sie of the file is less than 1 blocks in OpenVms

I might have 100's of files in a directory.
i want to delete those automatially when i run a COM.
that COM should automatically get all those which has size of 0 blocks and delete. I do not want to manually do it daily.
Highlighted
Valued Contributor

Re: To delete a file if the sie of the file is less than 1 blocks in OpenVms

You need:

HELP OPEN
HELP READ
HELP CLOSE

Craig
Highlighted
Trusted Contributor

Re: To delete a file if the sie of the file is less than 1 blocks in OpenVms


For an alternate method, try F$SEARCH, F$FILE_ATTRIBUTES and DELETE.
Highlighted
Honored Contributor

Re: To delete a file if the sie of the file is less than 1 blocks in OpenVms

In particular, you should look at lexical f$file_attributes, argument=EOF. This returns number of blocks used, zero-size file will return EOF=0

As suggested above, combine with an f$search and a delete command, in a loop.

DAve
Highlighted
Honored Contributor

Re: To delete a file if the sie of the file is less than 1 blocks in OpenVms

So you write a little DCL script around the produced file.

Or pipe it into a tool, like perl, which can take the list and turn it into a command.

For example:

$ pipe dir/sel=size=max=1/size=allo/nohead/notrail l*.*;* | perl -ne "chomp; unlink if /;/"

Or just let perl directly do the directory walk with a glob and do the size matching:

$ perl -e "for () {unlink unless -s}"

Too bad that DCL/DELETE does not take @ the way one would expect. It only takes the first line as filespec, the rest as commands.

Too bad $ DELETE does not take more 'common qualifiers'. It takes /since and /before but not /select.

Too bad DCL pipe does not come with an Unix XARGS like option.

You may also want to check out DFU HELP SEARC/FORMAT, but it's likely overkill.

( http://digiater.nl/dfu )

hth,
Hein
Highlighted

Re: To delete a file if the sie of the file is less than 1 blocks in OpenVms

HI All,

thanks for your quick response. will try tis out tomorrow.
Highlighted
Honored Contributor

Re: To delete a file if the sie of the file is less than 1 blocks in OpenVms

BE CAREFUL!...

realise that a file which is being written, open for exclusive access by another process, will be reported by F$FILE, DIRECTORY and DFU as size=0, even though it may contain large volumes of data. If you have sufficient privilege, you WILL be able to delete such a file. It will just be marked DELETE PENDING and be deleted when closed. If you're not careful you could delete real data, rather than just clean up a bunch of empty files.

You may want to check before blindly deleting such a file. You can try opening it for READ access:

$ SET NOON
$ OPEN/READ test candidate-file
$ IF $STATUS THEN CLOSE/DISPOSE=DELETE test

another option is to look at creation and modification dates (CDT and RDT). If exactly equal, the file is probably open.


Stepping back though... what is creating these files, and why do you get so many of them that you care enough to delete them?

Is there a way to detect them at the point they're created, rather than go hunting? For example:

$ out=some-file-name
$ do something which may generate output in 'out'
$
$ f=F$SEARCH(out)
$ IF f.NES.""
$ THEN
$ IF F$FILE(f,"EOF").LE.0 THEN DELETE 'f'
$ ENDIF

This way you KNOW the file is OK to be deleted.

If you must search whole disks, you may find DFU is quicker than DIRECTORY, especially on large volumes:

$ MCR DFU SEARCH/SIZE=MAX=0 device

A crucible of informative mistakes