xcopy忽略文件及常用参数 7zip打包
xcopy src target /Y /r /d /k /f /s /exclude:%cd%\xcopy.config
xcopy.config
\assets\
\tet\
7z.exe a -tzip %target%\target.zip src\*
xcopy 使用:
https://stackoverflow.com/questions/33752732/xcopy-still-asking-f-file-d-directory-confirmation
The /I switch (not /F as you mentioned in your question) prevents xcopy from asking whether the destination is a file or a directory only if multiple source files are given, so if the source is a directory, or if wildcards ? or * are used. If the destination already exists, such prompt does never appear.
There are the following scenarios (depending on the provided values of %source% and %target%):
-
a single source file, the destination is a file:
the
/Iswitch is useless, so you need to pipeFinto thexcopycommand line:echo F|xcopy /S /Q /Y /F "%source%" "%target%"provided that the
/Yswitch is given (to force overwriting), you could also create the target file in advance (empty file):>> "%target%" rem/ xcopy /S /Q /Y /F "%source%" "%target%" -
a single source file, the destination is a directory:
the
/Iswitch is useless too; you can pipeDinto thexcopycommand line:echo D|xcopy /S /Q /Y /F "%source%" "%target%"or you can simply append a
\to the destination:xcopy /S /Q /Y /F "%source%" "%target%\"although this causes trouble when
%target%specifies the current directory of a drive likeD:for instance, becauseD:means the current directory of this drive whereasD:\means the root directory of it;or you create the destination directory in advance:
2> nul mkdir "%target%" xcopy /S /Q /Y /F "%source%" "%target%"the
2> nulportion suppresses the error message in case the directory already exists; -
multiple source files, the destination is a file:
this is usually a senseless situation, because you tell
xcopyto copy each source file to the same destination file, thus attempting to overwrite it; -
multiple source files, the destination is a directory:
the
/Iswitch makes sense here:xcopy /S /I /Q /Y /F "%source%" "%target%"the pipe option also works here:
echo D|xcopy /S /Q /Y /F "%source%" "%target%"so does appending a
\to the destination (regarding the limitation as mentioned above):xcopy /S /Q /Y /F "%source%" "%target%\"or you create the destination directory in advance:
2> nul mkdir "%target%" xcopy /S /Q /Y /F "%source%" "%target%"
Conclusion
The most flexible and secure solution is to pipe the desired selection (F or D) into the xcopy command line. (Note that the query is locale-dependent.)
Supplement
There are some minor issues in your code fragment I want to mention here:
- you should generally use the
\as a path separator as this is the Windows standard character for that purpose (although/works too in most cases); - there is
-1111appended to your secondnet usecommand line; if this constitutes the password for the resource, it should be moved before the/USERoption; otherwise just remove it; - your
setcommand lines introduce problems with some special characters (like&,^,(,)); to avoid such, stateset "source=%~1"andset "target=p:/%~2"; the~removes potential surrounding""from the arguments (which are required if they contain SPACE,,,;,=);
Here is the code with the all of the above things reworked:
net use P: /DELETE
rem supposing `-1111` constitutes the password for the resource:
net use P: "\\200clan\F_Drive" -1111 /USER:adm /PERSISTENT:NO
set "source=%~1"
set "target=P:\%~2"
echo "%source%" "%target%"
rem supposing the destination is a directory:
echo D|xcopy /S /I /Q /Y /F "%source%" "%target%"
rem actually you do not need any interim variables:
REM echo D|xcopy /S /I /Q /Y /F "%~1" "P:\%~2"

浙公网安备 33010602011771号