Why is 'xcopy' Being Stymied?
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
-
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.
-
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 -
No cigar; instead, Formula is invalid: Unrecognized character in formula
-
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?
-
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?
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_bob said:You were running into a quirk in how the formula parser handles strings that end in a backslash.Regardless of the quirk, that did the trick - xcopy worked - thanks Bob!!!
-
FYI & FWIW - In regards, to v20 (b091018) (491), the double slash bug is still present.
-
kbellis said:FYI & FWIW - In regards, to v20 (b091018) (491), the double slash bug is still present.
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 -
Where exactly should that parameter be placed; i.e., before or after or in lieu of
NAME=
-
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 -
OKAY_GREAT="YES!" THANK_YOU_VERY_MUCH="TEST_NOW"
-
Am I the first to test this new parameter in the wild?
-
Or maybe the better question; is this FILENAME_PIECE parameter included in v20 (b091018) (491)?
-
VKB Edited 20180914 09:26Your 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.
-
Um... where does [Item #24907] inter into this discussion?
-
kbellis said:Um... where does [Item #24907] inter into this discussion?DEFINE_VARAdded a new value for the FILENAME_PIECE parameter: DIR_WO_SLASHDIR_LOOP_STARTAdded a new built-in variable: DIR_WO_SLASHLAYER_LOOP_STARTAdded 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 -
bmg_bob said:kbellis said:Um... where does [Item #24907] inter into this discussion?DEFINE_VARAdded a new value for the FILENAME_PIECE parameter: DIR_WO_SLASHDIR_LOOP_STARTAdded a new built-in variable: DIR_WO_SLASHLAYER_LOOP_STARTAdded 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
Categories
- 12.7K All Categories
- 5.6K Features Discussion
- 342 Downloading Imagery
- 1.3K Elevation Data
- 380 Georeferencing Imagery Discussion
- 628 GM Script Language
- 53 User Scripts
- 113 GPS Features
- 414 Projection Questions
- 819 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 177 Announcement and News
- 908 Bug Report
- 558 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 562 Other Discussion
- 129 GIS Data Sources
- 27 Global Mapper Showcase
- 233 How I use Global Mapper
- 107 Global Mapper Forum Website