OpenVMS Source Code Demos
DOWNCASE_FILENAMES.COM
$!============================================================
$! title : downcase_filenames.com
$! author: Neil Rieck
$! date : 2012-04-28
$!============================================================
$ set noon
$ say :== write sys$output
$ ask :== inquire/nopunct
$ files_scanned = 0
$ files_changed = 0
$!
$ say "============================="
$ say "title: downcase_filenames.com"
$ say "============================="
$ vms == f$getsyi("VERSION")
$ if (vms .les. "V7.2")
$ then
$ say "-w-oops, this program requires VMS version 7.2 or higher"
$ goto fini2
$ endif
$ if (p1 .eqs. "")
$ then
$ say "-w- no p1 detected"
$ say " a few one-liner examples: downcase file.ext"
$ say " downcase fi*le.ext"
$ say " downcase *.ext"
$ ask fs "filename spec? (default=exit) "
$ else
$ fs = p1
$ endif
$!~~~ say "fs: ",fs
$ if (f$locate(";",fs) .eqs. f$length(fs))!
$ then !
$ fs = fs + ";" ! we only want the latest version
$ endif !
$loop:
$ fqfs = F$SEARCH(fs) !
$ if fqfs .eqs. "" then goto fini ! exit if no more
$ fqfs = fqfs -""" -""" !
$ files_scanned = files_scanned + 1 !
$!
$ on error then goto fini ! prep trigger
$ set on ! arm trigger
$ set proc/case=sens/parse=extend !
$ my_dev = f$parse(fqfs,,,"DEVICE") !
$ my_dir = f$parse(fqfs,,,"DIRECTORY") !
$ my_nam = f$parse(fqfs,,,"NAME") !
$ my_typ = f$parse(fqfs,,,"TYPE") !
$ my_ver = f$parse(fqfs,,,"VERSION") !
$ fs1 = my_dev + my_dir + my_nam + my_typ ! needed for COS detection
$ fs2 = my_dev + my_dir + f$edit(my_nam,"LOWERCASE") + f$edit$(my_typ,"LOWERCASE")
$ if (fs1 .eqs. fs2) !
$ then !
$ same = 1 !
$ else !
$ same = 0 !
$ endif !
$ set proc/case=blind/parse=traditional !
$ set noon ! disarm trigger
$ if (same .eq. 1) then goto loop ! already lowercase
$!
$ say "okay to rename file: ", fqfs
$ say " to: ", fs2
$ ask choice "action? (y/n/q, default=N) "
$ if choice .eqs. "" then choice = "N"
$ if choice .eqs. "Q" then goto fini
$ if choice .eqs. "Y" !
$ then !
$ on error then goto fini ! prep handler
$ set on ! arm handler
$ set proc/case=sens/parse=extend !
$ rename/log 'fqfs' 'fs2' !
$ set proc/case=blind/parse=trad !
$ set noon ! disarm handler
$ endif !
$ say "====================================="
$ goto loop
$fini:
$ set proc/case=blind/parse=traditional
$ say "-i-files scanned: ",files_scanned
$ say " files changed: ",files_changed
$fini2:
$ say "-i-script exiting"
$ exit