At 11:31 2013-08-29, "James Harvey" <[email protected]> wrote:
Trying to copy pdf files from one folder to another and in the process
"rename" the files being copied.

The "name" is actually a tattoo number with a format like (5K7890, 6KB789,
KN1234), and we need the letters to be uppercase.

The process works, except that the destination file name will NOT maintain
the uppercase value.

[snip]

I ran into this problem a while back. I did not know about the Registry setting and came up with a VFP solution.

What I found is that if you try to create more than one level at once (directory/.../directory or directory/.../file), you get the lower case. Make sure that the target directory exists before doing the copy. Then, IME, case is preserved.

Ah, but what if the target directory does not exist? Well, before creating it, make sure that its parent exists. Recurse as needed.

I came up with a directory-creation procedure that builds the path piece by piece. Call mdnoerr() with the target directory then create the file.

***** Start of Included Code (Directory Creation) *****
* mdnoerr
* md with No Error if Directory Already Exists
* Last Modification: 2008-02-07
*
* Warning: Multi-level directory creation in one command works.  e.g. md \a\b
* will create both directories, but, apparently, if more than one level of
* directories does not already exist, the directory names are created in
* lower case regardless of the specified case.  Because of this bug, this
* procedure creates the directories one level at a time.

procedure mdnoerr
lparameters;
 thedir       && C: directory to create

   local which, where, saveerrh

   * Where to start md'ing

   do case

   * Volume share, as in
   *      \\server\sharename
   *      \\server\sharename\dir1\dir2
   * Skip md'ing on
   *      \\server\sharename\
   case left(thedir,2)="\\"
      which=5

   * Rooted path, as in
   *      c:\cbs2
   *      c:\cbs2\dir1\dir2
   * Skip md'ing on
   *      c:\cbs2\
   case isalpha(thedir) and substr(thedir,2,2)=":\"
      which=2

   * Non-rooted path, as in
   *      c:middle
   *      c:middle\sub2
   *      middle
   *      middle\sub2
   * No skipping.
   otherwise
      which=1
      endcase

   * Add a trailing backslash (which will be trimmed off) when creating the
   * last directory).
   if right(thedir,1)#"\"
      thedir=thedir+"\"
      endif

   where=at("\",thedir,which)

   do while where>0

      saveerrh=on("error")
      setupapperrh()
      md (left(thedir,where-1))
      on error &saveerrh

      do case
      case syserrno=1961
         * 1961: A directory or file already exists.: ignore.
      case syserrno#0
         error syserrno     && Rethrow any other error.
      otherwise
         * No error: do nothing.
         endcase

      which=which+1
      where=at("\",thedir,which)

      enddo

   return

   endproc
***** End of Included Code (Directory Creation) *****

***** Start of Included Code (Error Handler) *****
* setupapperrh
* Setup Error Handler for App-Level Code
* Last Modification: 2013-01-01

procedure setupapperrh

   syserrno=0

   syserrmsg=""
    && Kludge: This is to make sure that a spurious error code of 1 is not
    && generated by apperrh()'s kludge.  Since apperrh() will likely be
    && called only for individual statements and then the error handling
    && reset, this is fairly (but not totally) safe.

   on error apperrh(error(),message(),sys(2018),lineno(),lineno(1))

   return

   endproc



* apperrh
* Error Handler for App-Level Code
* Last Modification: 2007-05-02

procedure apperrh
lparameters perror, pmessage, psys2018, plineno, plineno1

   syserrno=perror
   syserrmsg=pmessage
   syserr2018=psys2018
   syserrlineno=plineno
   syserrlineno1=plineno1

   * Kludge: Sometimes, error()=0 when a file does not exist, yet message()
   * is set correctly!
   if syserrno=0 and !empty(syserrmsg)
      syserrno=1
      endif

   return

   endproc
***** End of Included Code (Error Handler) *****

Sincerely,

Gene Wirchenko


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to