Re: Changing Uppercase filenames into Lowercase

From: Fred Bach (music_at_triumf.ca)
Date: 08/17/05


Date: Tue, 16 Aug 2005 16:52:02 -0700

Aaron,

  Not a bad idea when it's ready. I don't like to post
  poor code, unreadable or uncommented code, or code with
  known bugs. Before today, MAKELOWER.COM worked, but had
  all four above problems.

  I made some progress today on tidying up and commenting
  MAKELOWER.COM so that it doesn't, when changing an
  uppercase filename to a lowercase filename, read the new
  lowercase filename as the next hit in the
  foundfile = f$search(filespec,1) command line.

  Actually it DOES read the new filename (!), and so that
  scenario had to be trapped out. I got myself into a few
  endless loops today that I had to CONTROL-Y out of, but the
  33rd revision seems to work fine. I'll wait a while, and put
  it in use here at the lab before posting it to dcl.openvms.org.
  I've seen some badly written code posted there, and complained
  about it, so I don't want to be guilty of my own complaints.
  (Frankly I think I could tidy up much of that code. Not that
  the code below is any great example....)

  Below is the current test copy of MAKELOWER.COM

  .. fred bach music@triumf.ca

$! MAKELOWER.COM Beta test version.
$! make all filenames lowercase in current working directory.
$! Created by F.W. Bach, TRIUMF Operations 09-AUG-2005
$! Based on a command procedure by Willem Grooters which was
$! posted on Friday June 18 2004 @ 03:42AM EDT ("MAKEUP.COM")
$! http://dcl.openvms.org/stories.php?story=04/06/18/6280218
$!
$! NOTE: This command procedure works when your DCL parse style is set
$! to Traditional, i.e., where
$! RENAME FRED.TMP fred.tmp
$! does NOT result in a lowercase fred.tmp file in the directory.
$!
$! To make the above command work, that is to make the RENAME command
$! recognize and produce lowercase filenames right from your DCL
$! command line WITHOUT using the ampersand ("&") technique below,
$! you will need to set your parse style this way:
$!
$! SET PROCESS/PARSE_STYLE=EXTENDED
$!
$! To restore the normal uppercasing of the whole, unquoted, DCL command
$! line:
$! SET PROCESS/PARSE_STYLE=TRADITIONAL
$!
$! See HELP SET PROCESS /PARSE_STYLE
$!
$! 12-AUG-2005 fwb. Add -Y arg for user to do all files without confirmation
$! For -Y, shift all cmd line args down one, for future use.
$! 16-AUG-2005 fwb. Catch & prevent looping on file already renamed to lower.
$! Show Foundfile each pass.
$! Add error message if no files found matching arg.
$! Add comments.
$!
$!
$! The first arg, P1, can be either a file name or pattern,
$! or it could be -y or -Y to override the confirm on rename.
$! In this latter case, the -y is dealt with, and all other
$! args on the command line are pulled forward by one
$! (i.e., p2 becomes p1, p3 becomes p2, p4 becomes p3, etc.).
$! This will eventually allow us the ability to specify upto
$! 6 other file names/patterns via the other args, some day.
$!
$! if p1 is -y or -Y,
$! then P2 is the filespec, which may include wildcards, if missing,
$! defaults to *.*;* in the current directory
$!
$! Will not rename directories.
$! Requires DELETE access on files (due to 'rename')
$! (THIS IS NOT CHECKED BEFOREHAND)
$!---------------------------------------------
$!
$ ver = f$verify(0)
$ say = "write sys$output"
$ set noon
$
$ if f$edit(p1,"UPCASE,COLLAPSE") .eqs. "-Y"
$ then
$ no_confirm = "TRUE"
$! since p1 was used up, walk forward all the arguments one step
$ p1 = p2 ! used now
$ p2 = p3 ! future use
$ p3 = p4 ! future use
$ p4 = p5 ! future use
$ p5 = p6 ! future use
$ p6 = p7 ! future use
$ p7 = p8 ! future use
$ p8 = ""
$ else
$ no_confirm = "FALSE"
$ say "Confirmation will be requested on all RENAMEs."
$ endif
$ searchspec = P1
$ if searchspec .eqs. "" then searchspec = "*.*;*"
$!
$! Loop through all files until done
$!
$ old_foundfile = "" !to prevent endless looping
$ pass = 0 !pass counter
$ searchspec = f$edit(searchspec,"lowercase,trim") !help prevent endless looping
$loop:
$ foundfile=""
$ foundfile=f$search(searchspec,1)
$ if foundfile .eqs. "" then goto end_loop
$ show symbol foundfile
$!
$! prevent endless looping on identical filename, filetype, fileversion...
$ if foundfile .eqs. old_foundfile then goto end_loop
$!
$! now we can save the foundfile as old_foundfile for use in next loop...
$ old_foundfile = foundfile
$!
$! NO case change if directory...
$ if f$file_attributes(foundfile,"DIRECTORY") then goto loop
$!
$ filedev =f$parse(foundfile,,,"DEVICE")
$ filepath=f$parse(foundfile,,,"DIRECTORY")
$ filename=f$parse(foundfile,,,"NAME")
$ filetype=f$parse(foundfile,,,"TYPE")
$ filevers=f$parse(foundfile,,,"VERSION")
$!
$! Now lowercase name and type...
$ lowername = f$edit(filename,"LOWERCASE")
$ lowertype = f$edit(filetype,"LOWERCASE")
$!
$! rename the original names to LOWER...
$ old_filename = foundfile
$ new_filename = filedev+filepath+lowername+lowertype+filevers
$!
$! *** Check first if this filename is ALREADY lowercase
$! *** and just put out a message if it is.
$!
$ if old_filename .eqs. new_filename
$ then
$! say "No need to rename ",old_filename," to ",new_filename
$ goto loop
$ endif
$ say old_filename," ==> ",new_filename
$ rename = "RENAME" ! in case it was redefined in login.com or define.com
$! ***
$! *** Use of the AMPERSAND symbol (&) prevents DCL uppercasing the
$! *** contents of the symbol new_filename, since the translation
$! *** of the symbol is done AFTER DCL interprets the command line.
$! ***
$ if no_confirm .eqs. "TRUE"
$ then
$ rename/log/noconfirm &old_filename &new_filename
$ else
$ rename/log/confirm &old_filename &new_filename
$ endif
$!
$ pass = pass + 1
$ goto loop
$!
$end_loop:
$ if pass .eq. 0
$ then
$ say "Sorry. No files matched pattern ''searchspec' to make lowercase."
$ endif
$ ver = f$verify('ver')
$ exit

Alphaman wrote:

> Fred Bach wrote:
>
>
>> But am I missing something easy?
>> .. fred bach music@triumf.ca
>
>
> Uhm, the only thing I can think of that is missing right now is these
> procedures being posted on dcl.openvms.org!
>
> Feel free to share them!
>
> Best,
> Aaron



Relevant Pages

  • Re: Pass command line file name parameter
    ... Then the document class has a copy of the filename, ... No need to access the original command line at all. ... want the user to see all the labels as they would be printed. ... filename or any other variable of your CWinApp class. ...
    (microsoft.public.vc.mfc)
  • Re: CStdioFile::Open gives error "No error occurred"
    ... I would avoid GetErrorMessage and just use FormatMessage on the error code itself, ... presume this is *not* the filename you planned to open, so why are you using m_lpCmdLine? ... there is a serious question here as to whether or not the command line has any ... Use the debugger, it is a very useful tool. ...
    (microsoft.public.vc.mfc)
  • Re: Cannot delete directory
    ... "Glenn" wrote in message ... > in a command window. ... >>window is a "normal" window. ... >>be a valid 8.3 filename - even if it has somehow been ...
    (microsoft.public.win2000.file_system)
  • Re: command line input and output
    ... Alternatively the first argument was a legal filename but it didn't exist, ... If there were no command line ... Microsoft Powerstation 4.0. ... qomputing dot demon dot co dot uk-- ...
    (comp.lang.fortran)
  • Re: 1.7 and Internal Reader
    ... lowercase letters are converted to ... one without the inclusion of IEFRDER. ... /S is how you issue a command to ... I could add IEFRDER and then UPPERCASE everything and when it ...
    (bit.listserv.ibm-main)