English 中文(简体)
为什么指挥XCOPY在批量档案中要求档案或文件夹?
原标题:Why does the command XCOPY in batch file ask for file or folder?

我的一位朋友从文字到文字上有一个简单的复印件,他从我的桌子上失踪20公里。

如果我的文件shapes.atc是档案或文件夹,那么在测试该笔文字时,我就会收到。

我可以告诉你,它是一个档案。 我怎么能与我的朋友一道自动复制这一文件,只需要两倍地点击批号,以便完成复印工作。

xcopy /s/y J:"My Name""FILES IN TRANSIT"JOHN20101126"Missing file"Shapes.atc C:"Documents and Settings""His name""Application Data"Autodesk"AutoCAD 2010""R18.0"enuSupportShapes.atc
问题回答

似乎无证件的骗局将在目的地结束时填写*,然后将xcopy作为文档复制,如上。

xcopy c:sourcefile.txt c:destination
ewfile.txt*

<代码>echo f copy ...... trick在瞬时不同的地方版视窗上工作。

实际上,Xcopy并没有问你原始档案是否存在,但是,如果你想把它放在一个名叫Shapes.atc的新手里,或者放在双手支持中(这是你想要的东西)。

为了防止影子提出这种要求,仅告诉他目的地的夹,因此没有含糊之处:

xcopy /s/y "J:Old pathShapes.atc" "C:Documents and Settingshis nameSupport"

如果你想要改变目的地的档案名称,只使用复印件(在复制档案时,该档案比复印件更适合):

copy /y "J:Old pathShapes.atc" "C:Documents and Settingshis nameSupportShapes-new.atc

真正的trick计是:在目标道路结束时使用斜lash,复制文档。 如果你不希望发出警告,Y要推翻现有档案。

<>>Example:

xcopy /Y "C:filefromhere.txt" "C:file	ohere"
echo f | xcopy /s/y J:"My Name""FILES IN TRANSIT"JOHN20101126"Missing file"Shapes.atc C:"Documents and Settings""His name""Application Data"Autodesk"AutoCAD 2010""R18.0"enuSupportShapes.atc

The /i switch might be what your after.

来源:

/I If destination does not exist and copying more than one file, assumes that destination must be a directory.

诚然,关于just me所要求的任务,根据

xcopy "J:My NameFILES IN TRANSITJOHN20101126Missing fileShapes.atc" "C:Documents and SettingsHis nameApplication DataAutodeskAutoCAD 2010R18.0enuSupport" /Q /R /S /Y

This works for this simple file copying task because of

  • specifying just the destination directory instead of destination file and
  • ending destination directory with a backslash which is very important as otherwise XCOPY would even with /I prompt for file or directory on copying just a single file.

与此无关的其他参数是:

  • /Q ... quiet
  • /Y ... yes (OS language independent) on overwrite existing file
  • /R ... overwrite also read-only, hidden and system file
  • /S ... from specified directory and all subdirectories.

在这里,我不知道是否真正需要<代码>/S,因为不清楚这是否只是J:My nameFILES IN TRANSITJOHN20101126Missing fileShapes.atc。 应复制或所有<代码>Shapes.atc在任何地方的名录树中发现的J:My nameFILES IN TRANSITJOHN20101126 遗失档案

对这些参数的解释可通过以下方式加以解读:打开指挥迅速窗口,从这个窗口中运行:xcopy /?,以获得XCOPY的帮助。


但是,所提供解决办法中没有一个用于复制档案任务,而单一档案应与源文档相仿,但由于目前的日期和时间,在档案延期之前就添加了不同的档案名称。

来文方档案中可以有隐藏的或系统特性,其中不包括使用<>COPY指令。

设定时间档的批量文件也应在视窗XP上工作,该台将ROBOCOPY排除在外,因为违约不能在Windows XP上查阅。

批量文档应当处理任何档案,包括非典型档案,如<代码>.gitconfig.htaccess,这些档案都是没有档案延期的,其起点是将其藏在*nix系统中。 视窗指挥处理员对档案等档案进行解释,这些档案没有档案名称,只是档案延期,因为最后一点是档案的延伸,最后一点是档案名称。

关于完整的任务说明和最后的、经过充分评论的解决方案,见。 在“紫外线”中创建文档备份 Edit论坛。

https://stackoverflow.com/a/35319710/3074564>,Patrick s ,,>Interociter Businesstor s,CharlesB s 解决办法不奏效,因为使用<代码/Y,如果没有目的地,就无法避免档案或目录。

https://stackoverflow.com/a/43041/3074564>Andy Morris grenix s Solutionst t 可用于单一档案复制任务,因为目的地必须是目的地名称,而不是目的地名录名称。 目的地名录与来源目录相同,但目的地档案名称与来源档案名称不同。

DosMan sGovert s 解决办法根本不能从某一点开始就档案工作,而没有档案延期。

例如,指挥

xcopy C:Temp.gitconfig C:Temp.gitconfig_2016-03-07_15-30-00* /C /H /K /Q /R /V /Y

产生以下执行错误信息:

English:  Could not expand second file name so as to match first.
German: Zweiter Dateiname konnte nicht so erweitert werden, dass er zum ersten passt.

最后,Denis Ivin s 解决办法有限制,即必须知道操作系统语言的附属特性,即自动回答OR目录。

因此,我想到在德国Windows或上为<<<<<>而在英文Windows或上<上<德国Windows>或上<<<>>>>>>>?, ......>。 视窗自动使用。

确实可以确定自动回答迅速的语文属性。

一个黑板用来从即时文本中获取语文附属信件,而没有真正复制任何档案。

<>XCOPY指挥部用于开始复制批量档案,以复制临时档案,并将档案延期作为目的地档案。 如果在临时档案中没有这种名字的档案,而这种档案不太可能。

<NUL 装置的手稿被作为投稿人,用于XCOPY,导致在速成XCOPY两倍后中断复制过程。

这一产出的处理方式是FOR loop,从开端母体开始,先从第一行开始。 这是第二大特征界定了用于确定目的地为档案的文字。

此处是使用XCOPY的批量文档,其编号是确定自动对文档或目录进行答复的必要信函,从而在源文档中以与源文档相同的目录制作一个时间封存的单一档案副本,即使来文方档案是隐蔽的或系统档案,即使来文方档案从某一点开始,没有档案延期。

@echo off
setlocal EnableExtensions DisableDelayedExpansion
rem Batch file must be started or called with name of a single file.

if "%~1" == "" exit /B
for /F "delims=*?" %%I in ("#%~1#") do if not "%%I" == "#%~1#" exit /B
if not exist "%~1" exit /B
if exist "%~1" exit /B

rem Determine the character needed for answering prompt of
rem XCOPY for destination being a file and not a directory.

del /F "%TEMP%\%~n0.tmp" 2>nul
for /F %%I in ( %SystemRoot%System32xcopy.exe "%~f0" "%TEMP%\%~n0.tmp" ^<nul ) do (
    set "PromptAnswer=%%I"
    setlocal EnableDelayedExpansion
    if "!PromptAnswer:~0,1!" == "(" set "PromptAnswer=!PromptAnswer:~1,1!" & goto CopyFile
    endlocal
)
echo ERROR: Failed to determine letter for answering prompt of XCOPY.
exit /B

:CopyFile
endlocal & set "PromptAnswer=%PromptAnswer%"
rem This is a workaround for files starting with a point and having no
rem file extension like many hidden files on *nix copied to Windows.

if "%~n1" == "" (
    set "FileNameWithPath=%~dpx1"
    set "FileExtension="
) else (
    set "FileNameWithPath=%~dpn1"
    set "FileExtension=%~x1"
)

rem Get local date and time in region and language independent format YYYYMMDDHHmmss
rem and reformat the local date and time to format YYYY-MM-DD_HH-mm-ss.

for /F "tokens=2 delims==." %%I in ( %SystemRoot%System32wbemwmic.exe OS get LocalDateTime /format:value ) do set "LocalDateTime=%%I"
set "LocalDateTime=%LocalDateTime:~0,4%-%LocalDateTime:~4,2%-%LocalDateTime:~6,2%_%LocalDateTime:~8,2%-%LocalDateTime:~10,2%-%LocalDateTime:~12,2%"

rem Do the copy with showing what is copied and with printing success or
rem an error message if copying fails for example on sharing violation.

echo Copy "%~f1" to "%FileNameWithPath%_%LocalDateTime%%FileExtension%"

for /F %%I in ( echo %PromptAnswer% ^| %SystemRoot%System32xcopy.exe "%~f1" "%FileNameWithPath%_%LocalDateTime%%FileExtension%" /C /H /K /Q /R /V /Y ) do set "FilesCopied=%%I"

if "%FilesCopied%" == "1" (echo Success) else echo ERROR: Copying failed, see error message above.

这一批量代码在德国Windows XP SP3 x86和英国Windows 71 x64上测试。

。 在“紫外线”中创建文档备份 Edit Forum for a similar, full comment batch file Interpretation all aspects of the batch Code.

为了了解所使用的指挥和他们如何工作,打开指挥迅速窗口,在那里执行以下指挥,并非常仔细地阅读了每个指挥员所展示的所有求助网页。

  • del /?
  • echo /?
  • exit /?
  • for /?
  • goto /?
  • if /?
  • rem /?
  • set /?
  • setlocal /?
  • wmic OS get /?
  • xcopy /?

关于

当新的延长期限较短时,可以把“*”引向工作。 你们需要把新展期与带刺刀,这只能通过在报价中填入目的地名称来实现。 例如:

xcopy foo.shtml "foo.html *"

这将复制并改名,而不迅速。

“不是ug”,它带有一个特征。 (我曾看到Microsoft停车场的VW Beetle,车牌是“常规”) 这些名词在我写到监督事务司诉1时完全回头。 新名称的特征,除非有新名称的野心特性(? 或 *)在场,否则以旧名称代替。 如果不在新名称中添加空白,其余特征就用旧名称复制。

xcopy /s/y J:"My Name""FILES IN TRANSIT"JOHN20101126"Missing file"Shapes.atc C:"Documents and Settings""His name""Application Data"Autodesk"AutoCAD 2010""R18.0"enuSupport*.*"

......应该这样做。

Good idea to do an:

IF NOT EXIST "C:Documents and SettingsHis nameApplication DataAutodeskAutoCAD 2010R18.0enuSupportShapes.atc" ECHO/ && ECHO/ && ECHO * * * * * COPY FAILED - Call JustME at 555-555-1212 && ECHO/ && pause

(假设你将以前的版本改名为老)

XCOPY  /Z  <----- restartable mode - good for large files.

The virtual parent trick

假设您的源头和目的地档案

%SRC_FILENAME% and %DST_FILENAME%

您可使用两步方法:

@REM on my win 7 system mkdir creates all parent directories also
mkdir "%DST_FILENAME%.."
xcopy "%SRC_FILENAME% "%DST_FILENAME%.."

这一点可以解决,例如:

mkdir "c:destinationcfile.txt.."
@REM The special trick here is that mkdir can create the parent
@REM directory of a "virtual" directory (c:destinationcfile.txt) that 
@REM doesn t even need to exist.
@REM So the directory "c:destinationc" is created here.
@REM mkdir "c:destinationcdummystring.." would have the same effect

xcopy "c:sourcecfile.txt" "c:destinationcfile.txt.."
@REM xcopy computes the real location of  "c:destinationcfile.txt.."
@REM which is the now existing directory "c:destinationc"
@REM (the parent directory of the "virtual" directory c:destinationcfile.txt).

I came to the idea when I stumbled over some really wild ../..-constructs in the command lines generated from a build process.

I had exactly the same problem, where is wanted to copy a file into an external hard drive for backup purposes. If I wanted to copy a complete folder, then COPY was quite happy to create the destination folder and populate it with all the files. However, I wanted to copy a file once a day and add today s date to the file. COPY was happy to copy the file and rename it in the new format, but only as long as the destination folder already existed.

我的指挥系统认为:

<>COPY C:SRCFOLDERMYFILE.doc D:DESTFOLDERMYFILE_YYYYMMDD.doc

Like you, I looked around for alternative switches or other copy type commands, but nothing really worked like I wanted it to. Then I thought about splitting out the two different requirements by simply adding a make directory ( MD or MKDIR ) command before the copy command.

现在

http://www.ohchr.org。 D. 经社事务部

<>COPY C:SRCFOLDERMYFILE.doc D:DESTFOLDERMYFILE_YYYYMMDD.doc

If the destination folder does NOT exist, then it creates it. If the destination folder DOES exist, then it generates an error message.. BUT, this does not stop the batch file from continuing on to the copy command.

The error message says: A subdirectory or file D:DESTFOLDER already exists

正如我说过的那样,错误信息并没有阻止批量文件的工作,而是解决问题的真正简单办法。

希望这一帮助。





相关问题
complex batch replacement linux

I m trying to do some batch replacement for/with a fairly complex pattern So far I find the pattern as: find ( -name *.php -o -name *.html ) -exec grep -i -n hello {} + The string I want ...

How to split a string by spaces in a Windows batch file?

Suppose I have a string "AAA BBB CCC DDD EEE FFF". How can I split the string and retrieve the nth substring, in a batch file? The equivalent in C# would be "AAA BBB CCC DDD EEE FFF".Split()[n]

How to check which Operating System?

How can I check OS version in a batch file or through a vbs in an Windows 2k/2k3 environment ? You know ... Something like ... : "If winver Win2k then ... or if winver Win2k3 then ....