Why is 'xcopy' Being Stymied?

kbelliskbellis Global Mapper UserPosts: 514Trusted User

When I run the xcopy straight from a DOS prompt, without a variable, and a regular path, it works. But in the Global Mapper script, trying to use a variable, the script just hangs. Is there an extra backslash being added by Global Mapper?

Best Answers

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 1,834
    Answer ✓
    kbellis said:
    Reading from ancient posts here on the forum, apparently in days of old, variables weren't permitted to be passed to the RUN_COMMAND, but now it seems this really hasn't exactly changed insofar as dir level commands are concerned, like xcopy. Or is it something else at play?
    Variables are permitted in RUN_COMMAND, so that is not an issue.  You were running into a quirk in how the formula parser handles strings that end in a backslash. Without getting into too much detail, the final apostrophe was being treated as part of the data instead of the end-of-string indicator. Here is a version of the command that will work:

    DEFINE_VAR NAME="DIR_NO_SLASH" FORMULA="LEFT('%SPECIFIED_SOURCE_IMAGE_DIR% ',LEN('%SPECIFIED_SOURCE_IMAGE_DIR% ')-2)"

    Note that the blank before the ending apostrophe after %SPECIFIED_SOURCE_IMAGE_DIR% is necessary to overcome the issue described above.  It would also be a good idea to make sure that directory names can be returned without the trailing backslash, if desired, so I will open a bug for that.

    Cheers,
    Bob
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 1,834
    Answer ✓
    Hello Kelly,

    It would look something like this:
    DEFINE_VAR NAME="NO_SLASH" PROMPT="DIR" FILENAME_PIECE="DIR_WO_SLASH"
    The FILENAME_PIECE parameter lets you choose to use all or just a part of the name that gets returned via the prompt.  If it is not included in the command, then the entire directory name, including the trailing slash, will be returned.

    Cheers,
    Bob

Answers

  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    edited August 21
    Simply adding the bit /C (/C Carries out the command specified by string and then terminates) allowed the script to run without hanging. However, the xcopy failed to actually work.



  • bmg_bobbmg_bob Global Mapper Programmer Posts: 1,834
    Hello,

    It appears that the trailing slash is causing problems for xcopy.  Here is a command that should remove the trailing slash from your directory:
    DEFINE_VAR NAME="DIR_NO_SLASH" \
      FORMULA="LEFT(%SPECIFIED_SOURCE_IMAGE_DIR%, LEN(%SPECIFIED_SOURCE_IMAGE_DIR%)-1)"
    It copies all but the last character from %SPECIFIED_SOURCE_IMAGE_DIR% to %DIR_NO_SLASH%.  You can do the same for your other directly, then use the 'no slash' directories in your xcopy command.

    Cheers,
    Bob
  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    edited August 21
    No cigar; instead, Formula is invalid: Unrecognized character in formula



  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    Reading from ancient posts here on the forum, apparently in days of old, variables weren't permitted to be passed to the RUN_COMMAND, but now it seems this really hasn't exactly changed insofar as dir level commands are concerned, like xcopy. Or is it something else at play?
  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    edited August 22

    bmg_bob said:
    You were running into a quirk in how the formula parser handles strings that end in a backslash.
    Wasn't it more of a quirk of handling strings that DON"T, or at least aren't supposed to end in a backslash? i.e., any operation on a folder?

    Regardless of the quirk, that did the trick - xcopy worked - thanks Bob!!!



  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    FYI & FWIW - In regards, to v20 (b091018) (491), the double slash bug is still present.
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 1,834
    kbellis said:
    FYI & FWIW - In regards, to v20 (b091018) (491), the double slash bug is still present.
    Could you clarify what you mean by "double slash bug"? 

    If it has to do with the trailing backslash when you prompt for a directory in DEFINE_VAR, you can use the new FILENAME_PIECE="DIR_WO_SLASH" parameter on that command to get the directory name with no trailing slash.

    Cheers,
    Bob
  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    Where exactly should that parameter be placed; i.e., before or after or in lieu of
    NAME=
  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    OKAY_GREAT="YES!" THANK_YOU_VERY_MUCH="TEST_NOW" 


  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    Am I the first to test this new parameter in the wild?
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 1,834
    kbellis said:
    Am I the first to test this new parameter in the wild?
    It's quite possible that you are.  It will not be in the documentation until Global Mapper 20 is out.

    Cheers,
    Bob
  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    Or maybe the better question; is this FILENAME_PIECE parameter included in v20 (b091018) (491)?
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 1,834
    kbellis said:
    Or maybe the better question; is this FILENAME_PIECE parameter included in v20 (b091018) (491)?
    Yes.
  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    edited September 14
    VKB Edited 20180914 09:26

    Your string trim workaround option works, the FILENAME_PIECE parameter doesn't... at least not as I thought it would at first.

    The reason I thought that it didn't work, and I certainly was mistaken, is the context of the script wherein there is a call for the defined variable to, say for example, store the log.txt. Using the new parameter prevents that log.txt from being saved. So in this context the slash mark is needed; i.e., all pieces.

    In other words, your string trim work around accommodates directory-wide command line operations, like xcopy, by creating a separate variable. And apparently, the new parameter FILENAME_PIECE is a more compact version of your original workaround.

  • kbelliskbellis Global Mapper User Posts: 514Trusted User
    Um... where does [Item #24907] inter into this discussion?
Sign In or Register to comment.