Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 复制路径中带有通配符的文件_Batch File - Fatal编程技术网

Batch file 复制路径中带有通配符的文件

Batch file 复制路径中带有通配符的文件,batch-file,Batch File,假设存在目录结构C:\users\myuser\Desktop\bob\marley 在windows中,我可以从起始目录C:\users\myuser\Desktop执行“cd bo*\mar*”操作,并将cd放入目录bob\marley中。但是,我不能“复制bo*\mar*C:\” 我需要使用copy、xcopy或一些在路径中带有通配符的标准windows命令将匹配目录复制到目标。我不确定这是否是copy和xcopy的限制,或者我的语法是否错误。我还尝试过“xcopy/E/I bo*\mar

假设存在目录结构C:\users\myuser\Desktop\bob\marley

在windows中,我可以从起始目录C:\users\myuser\Desktop执行“cd bo*\mar*”操作,并将cd放入目录bob\marley中。但是,我不能“复制bo*\mar*C:\”


我需要使用copy、xcopy或一些在路径中带有通配符的标准windows命令将匹配目录复制到目标。我不确定这是否是copy和xcopy的限制,或者我的语法是否错误。我还尝试过“xcopy/E/I bo*\mar**C:\somedirectory”。

否-您不能使用COPY或xcopy。你问的问题有一个根本性的缺陷

如果您还有一个名为“boston\marathon”的目录呢?您要从哪个目录复制

你可以回答:“我两者都想要”。但现在你有一个严重的潜在问题。如果两个源目录都包含一个名为“test.txt”的文件,该怎么办。目标中只能有一个名为“test.txt”的文件。你留着哪一个?没有正确的答案,这就是为什么命令设计为不允许您尝试执行的操作的一个很好的原因

附录

如果您愿意假设只有一个文件夹与该模式匹配,那么您已经知道通过以下步骤实现目标的所有步骤

@echo off
cd bo*\ma*
xcopy * c:\somedirectory
如果要返回到开始的位置,请使用PUSHD/POPD而不是CD

@echo off
pushd bo*\ma*
xcopy * c:\somedirectory
popd

但是,你应该非常小心。Boston\marathon可能存在,PUSHD和CD都不会显示存在潜在问题。

如果要复制所有匹配目录的所有文件。你仍然可以这样做

for /d %%d in (bo*) do (
  for /d %%e in (ma*) do (
     copy %%d\%%e\* c:\temp
但是,当同名文件出现在不同的目录中时,要小心。

RusF。注: 在使用XCOPY时,无法再在中使用通配符 文件名的目录,然后只是有一组类似的 已将命名目录复制到存档或网络结构

(提示:如果您正在管理,您希望一直这样做 大量数据。例如视频或电影文件(其中包含许多文件) 可能与生产关联。或与价格历史数据关联 不同格式的文件,或来自不同 研究项目或实验工作。)

我确信我以前可以用旧的XCOPY做到这一点,但是 对于升级(为了安全),文件名中的通配符 无法正常工作(即,您可以构建目录结构, 使用“/t”选项,但无法在其中获取该死的文件 要迁移的目录!该死的烦人。)

嗯,我们在农场,总能找到解决办法,即使 需要使用.44万能或Styer 50.:)

所以,我想到的是:

假设你有一堆名为“Fark_1,Fark_2”的目录, Fark Special,Fark_in_the_Park,Fark99…“等等

如果所有这些“Fark…”目录都存在于C:\磁盘上,并且 您想将此子结构的副本迁移到存档 网络上的磁盘(说它叫:“h:”)你可以 请执行以下操作:

从Windows(MS-DOS)命令提示符运行FOR DO:

 c:\>  XCOPY  fark*  h: /s /e /f /t

            The /s /e are for copying subdirs
            and empty directories, the /f says to
            show the files, and the /t says to only
            copy the disk directories.  No XCOPY
            option seems to exist anymore to copy the
            disk structure AND the files in the
            directories.
 FOR /d %a in (fark*) DO XCOPY "%a" h:%a\ /s /e /f /h /k /y

            The /d says we are using directory names.
            The %a is the variable name, substituted
            into the command script for XCOPY. Make
            sure to use whatever logical name or drive
            letter you have for your archive structure.
            (ie. don't use h: in the above command,
            unless you have mapped h: to the place on
            the network where you want to copy your
            files to.)  And note, the /y option means
            overwrite any files already there.
要复制文件,请执行以下操作:, 也可以从Windows命令提示符:

 c:\>  XCOPY  fark*  h: /s /e /f /t

            The /s /e are for copying subdirs
            and empty directories, the /f says to
            show the files, and the /t says to only
            copy the disk directories.  No XCOPY
            option seems to exist anymore to copy the
            disk structure AND the files in the
            directories.
 FOR /d %a in (fark*) DO XCOPY "%a" h:%a\ /s /e /f /h /k /y

            The /d says we are using directory names.
            The %a is the variable name, substituted
            into the command script for XCOPY. Make
            sure to use whatever logical name or drive
            letter you have for your archive structure.
            (ie. don't use h: in the above command,
            unless you have mapped h: to the place on
            the network where you want to copy your
            files to.)  And note, the /y option means
            overwrite any files already there.
是的,这是老式的unix/dos,但它可以工作,而且 您可以将其放入批处理作业中。你可以避免成为 用鼠标垫来完成工作。(指向、点击、咕哝、诅咒。 重复。使用GUI的规范过程,对吗?) 现在,有很多新奇的方法可以做到这一点。各种各样 UTIL如Robocopy、XXcopy等。但这就明白了 完成,如果您有Windows的任何副本,您可能 已经有了XCOPY和待办事项。祝你一切顺利。 哦,如果将这两个命令放入批处理作业中,那么 必须调整两级命令的语法 替换(我认为是正确的术语)

批处理示例:

 REM --- copy the "fark*" files to the archive disk h:
 @echo off
 REM --- create/update the structure 
 xcopy fark* h: /s /e /f /t
 REM --- copy over the fark* dirs, and all associated subdirs
 for /d %%a in (fark*) do xcopy "%%a" "h:%%a\" /s /e /f /h /k /y
  • 俄罗斯的未来 2012年4月18日

这是我的批处理脚本,用于使用上述帮助将一些文件夹备份到一个驱动器,将一些文件夹备份到另一个驱动器-适用于Win 7 great

如果使用FOR循环和/S只复制更改的内容,则无需复制文件夹结构

很遗憾你不能在这里使用正则表达式——或者有人有更简洁的解决方案吗

FOR /d %%a in (2010* 2011* 2012* 201301* 2013020* 2013021* 20130222* 20130224*) DO (
  XCOPY "%%a" "Z:\Backup\My Videos\%%a\" /D /S /Y | findstr /V "0 File"
)
FOR /d %%a in (20130225* 201303*) DO (
  XCOPY "%%a" "X:\Backup\My Videos\%%a\" /D /S /Y | findstr /V "0 File"
)

因此,如果您知道目录名,我不知道您为什么尝试使用通配符。我在使用Mozilla Firefox时遇到了一个问题,我们使用的许多网站都需要公共访问卡认证。默认情况下,Mozilla Firefox未配置为使用CAC阅读器。所以我用CAC阅读器配置了我的Firefox,然后从我的用户目录C:\Users\%myname%\AppData\Roaming\Mozilla\Firefox\Profiles\中抓取了cert8.db和secmod.db文件。默认值

问题是,当我不知道谁登录到哪台计算机和???????时,将这些文件复制到多台计算机和多个用户目录。默认文件夹的名称对于每个用户都不同

我创建了一个名为Computers.txt的文本文件,输入从Active Directory检索到的计算机列表,然后编写以下脚本来复制包含CAC设备的.db文件,并将其复制到C:\Temp\Security

for /f %c in (C:\Temp\Computers.txt) do for /f %u in ('dir /B \\%c\C$\Users\') do for /f %m in ('dir /B \\%c\C$\Users\%u\AppData\Roaming\Mozilla\Firefox\Profiles\') do copy /Y C:\Temp\Security\*.db \\%c\C$\Users\%u\AppData\Roaming\Mozilla\Firefox\Profiles\%m\*

回答得好。我明白你在说什么。假设我知道只有一个目录路径匹配,但我事先不知道完整路径是什么(即自动生成的日期),您建议如何完成副本?我想到了这一点,但您需要为每个目录级别创建一个新的FOR循环。我假设水平的数量也不同。