I have an intune package which runs a batch script as follows.
SET INST=%~dp0
xcopy %INST%\Folder1\* "C:\Program Files (x86)\Test\Folder2" /s /i
Goal is to copy files from Folder1 to Folder2. The Batch script and folder 1 are in the same main folder. No files are being copied so I'm confused.
Thanks,
The two command lines could be replaced by the single command line:
The batch file with this command line needs to be run as administrator because of the directory referenced with
%ProgramFiles(x86)%is usually write-protected for standard users.The help output on running
cmd /?in a command prompt window explains on last help page that a file name (or any other argument string like a password) containing a space or one of these characters&()[]{}^=;!'+,`~(or literally to interpret<>|as in a password) must be enclosed in"to be interpreted as one argument string on which all characters are interpreted literally with the exception of%and!if delayed expansion is enabled on parsing the command line in the batch file. It is advisable to enclose file/folder argument strings always in double quotes if there is not guaranteed that"are not needed as for%SystemRoot%\System32\xcopy.exe.The Windows command XCOPY is specified with fully qualified file name. That improves efficiency as the Windows Command Processor does not need to search in file system for an executable/script with file name
xcopyin current directory and in the directories listed separated with semicolons in value of local environment variablePATHwith a file extension listed in value of local environment variablePATHEXT. The usage of the fully qualified file name makes this command line also fail safe because of noxcopy.cmdin current directory or a corruptedPATHnot containing anymore%SystemRoot%\System32can cause anymore a different execution of this command line than the expected one.There is no backslash between
%~dp0andFolder1in source argument string because of%~dp0always expands to full path of the directory containing the batch file ending with\. So the resulting argument string of%~dp0Folder1is 100% valid which must not be modified in any way by the Windows file I/O functions before passing the directory argument string to the file system.There can be appended to source argument string
\*, i.e. use"%~dp0Folder1\*"as first argument string for XCOPY, but copying all files in the specified source directory, and with option/Salso all files in non-empty directories, is the default.The destination argument string ends with a backslash. That makes it 100% clear for XCOPY that the destination is a directory. That backslash at end makes it unnecessary to use option
/I. XCOPY creates always the entire directory tree to the destination directory. The destination is definitely a directory with destination argument string ending with a backslash.The usage of XCOPY is deprecated since Windows Vista and Windows Server 2003 on which ROBOCOPY is installed by default in the Windows system directory. ROBOCOPY is a more robust and more powerful file/directory copying/moving program. Run in a command prompt window
robocopy /?for output of its usage help or read the Microsoft documentation for robocopy.The same directory copying task can be done with ROBOCOPY with:
ROBOCOPY creates also the entire destination directory tree if that is necessary.
It is important to mention that
robocopy.exeuses a special argument string parsing likereg.exe. A\left to one more\or a"is interpreted as escape character for the following backslash or double quote character. For that reason no argument string of ROBOCOPY enclosed in"should end with a single backslash as that would be interpreted as escape for the double quote and so everything up to next"is interpreted as one argument string although a directory path cannot contain the character"at all.Valid ROBOCOPY command lines are regarding to source and destination:
Invalid ROBOCOPY command lines are regarding to source and destination:
The first line is invalid as
%~dp0could expand to a string containing a space or one of these characters&()[]{}^=;!'+,`~and%ProgramFiles(x86)%expands by default to a string containing a space and both round brackets and therefore source and destination path must be enclosed in double quotes.If the root directory of a drive is the source or destination on which it is necessary that the directory path ends with a backslash, it is best not enclosing the root directory path like
C:\orD:\in double quotes.