Global Mapper v25.0

Why is 'xcopy' Being Stymied?

kbellis
kbellis Global Mapper UserTrusted 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?

Answers

  • kbellis
    kbellis Global Mapper User Trusted User
    edited August 2018
    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_bob
    bmg_bob Global Mapper Programmer
    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
  • kbellis
    kbellis Global Mapper User Trusted User
    edited August 2018
    No cigar; instead, Formula is invalid: Unrecognized character in formula



  • kbellis
    kbellis Global Mapper User Trusted 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?
  • bmg_bob
    bmg_bob Global Mapper Programmer
    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
  • kbellis
    kbellis Global Mapper User Trusted User
    edited August 2018

    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!!!



  • kbellis
    kbellis Global Mapper User Trusted User
    FYI & FWIW - In regards, to v20 (b091018) (491), the double slash bug is still present.
  • bmg_bob
    bmg_bob Global Mapper Programmer
    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
  • kbellis
    kbellis Global Mapper User Trusted User
    Where exactly should that parameter be placed; i.e., before or after or in lieu of
    NAME=
  • bmg_bob
    bmg_bob Global Mapper Programmer
    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
  • kbellis
    kbellis Global Mapper User Trusted User
    OKAY_GREAT="YES!" THANK_YOU_VERY_MUCH="TEST_NOW" 


  • kbellis
    kbellis Global Mapper User Trusted User
    Am I the first to test this new parameter in the wild?
  • bmg_bob
    bmg_bob Global Mapper Programmer
    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
  • kbellis
    kbellis Global Mapper User Trusted User
    Or maybe the better question; is this FILENAME_PIECE parameter included in v20 (b091018) (491)?
  • bmg_bob
    bmg_bob Global Mapper Programmer
    kbellis said:
    Or maybe the better question; is this FILENAME_PIECE parameter included in v20 (b091018) (491)?
    Yes.
  • kbellis
    kbellis Global Mapper User Trusted User
    edited September 2018
    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.

  • kbellis
    kbellis Global Mapper User Trusted User
    Um... where does [Item #24907] inter into this discussion?
  • bmg_bob
    bmg_bob Global Mapper Programmer
    Answer ✓
    kbellis said:
    Um... where does [Item #24907] inter into this discussion?
    Item #24907 added the ability for directory names in a script to be returned without a trailing backslash ("\") in the following contexts:

    DEFINE_VAR

    Added a new value for the FILENAME_PIECE parameter: DIR_WO_SLASH

    DIR_LOOP_START

    Added a new built-in variable: DIR_WO_SLASH

    LAYER_LOOP_START

    Added a new built-in variable: LAYER_DIR_WO_SLASH (As with other built-in variables that are part of LAYER_LOOP_START, "LAYER" is a default prefix. There is a parameter that allows the user to define a different prefix.)

    The changes were checked in to GM 20 on Wednesday, August 22, 2018 3:55:46 PM

  • kbellis
    kbellis Global Mapper User Trusted User
    bmg_bob said:
    kbellis said:
    Um... where does [Item #24907] inter into this discussion?
    Item #24907 added the ability for directory names in a script to be returned without a trailing backslash ("\") in the following contexts:

    DEFINE_VAR

    Added a new value for the FILENAME_PIECE parameter: DIR_WO_SLASH

    DIR_LOOP_START

    Added a new built-in variable: DIR_WO_SLASH

    LAYER_LOOP_START

    Added a new built-in variable: LAYER_DIR_WO_SLASH (As with other built-in variables that are part of LAYER_LOOP_START, "LAYER" is a default prefix. There is a parameter that allows the user to define a different prefix.)

    The changes were checked in to GM 20 on Wednesday, August 22, 2018 3:55:46 PM

    Thank you Bob!