MSDOS 命令将目录结构中匹配模式的文件复制到本地目录

发布于 2024-12-06 16:54:27 字数 638 浏览 1 评论 0原文

我有一项定期运行并将文件存档到如下所示的文件夹结构中的作业:

ArchiveFolder
    TimestampFolder
        JobnameFolder
            job<timestamp>.xml

对于给定的作业,我想将存档文件夹中的所有 xml 文件收集到一个平面目录中(没有子目录,只有所有文件)无需深入研究每一项,检查正确的作业,然后复制文件。

似乎应该有一种相当简单的方法来做到这一点。有什么建议吗?

编辑:我想我在这里不清楚。 TimeStampFolder 的名称类似于 2011-07-24,JobnameFolder 的名称类似于 FooFeedBarFeed,作业的名称类似于 FooFeedBarFeed。文件的名称类似于 job2011-07-24.xml。 TimeStampFolder 有成百上千个,每个 TimeStampFolder 中可能有一个或多个作业文件夹。给定一个特定的作业名称,我想收集与该作业类型匹配的所有目录中的所有文件,并将它们转储到本地文件夹中,没有子目录。

I have a job that periodically runs and archives files into a folder structure that looks like this:

ArchiveFolder
    TimestampFolder
        JobnameFolder
            job<timestamp>.xml

For a given job, I'd like to collect all xml files in the archive folder into a flat directory (no subdirectories, just all the files) without having to drill down into each one, examine for the proper job, then copy the file.

It seems there should be a fairly straigtforward way of doing this. Any suggestions?

EDIT: I guess I wasn't clear here. The TimeStampFolder will have a name of something like 2011-07-24, the JobnameFolder will have a name like FooFeed or BarFeed, and the job file will have a name like job2011-07-24.xml. There are hundreds to thousands of TimeStampFolders, and each one may have one or more job folders in it. Given a specific job name, I want to collect all the files in all the directories that match that job type, and dump them into the local folder, with no subdirectories.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠北森屋 2024-12-13 16:54:27

EDIT1:

SET JOB=JobName
SET OF=OutputFolder

START /wait NET USE Z: "\\ServerName\Sharename\ArchiveFolder" password password_here /USER:domainname\username /P:NO
PUSHD Z:\
FOR /F "USEBACKQ tokens=*" %%A IN (`DIR /b /a:d /s ^| FIND /I "%JOB%"`) DO (
 FOR /R %%F IN (%%A) DO (
  COPY /Y "%%~fF" "%OF%"
 )
)
POPD

它基本上找到了 ArchiveFolder 中包含 JobName 的每个子目录,然后深入到它找到的每个子目录中,以从中复制文件。

EDIT2:

添加了 NET USE 来访问网络共享以对文件执行任务。如果您的本地计算机已将 UNC 分配给驱动器号,则可以删除 NET USE 命令行并将 Z: 更改为分配的驱动器号。

EDIT1:

SET JOB=JobName
SET OF=OutputFolder

START /wait NET USE Z: "\\ServerName\Sharename\ArchiveFolder" password password_here /USER:domainname\username /P:NO
PUSHD Z:\
FOR /F "USEBACKQ tokens=*" %%A IN (`DIR /b /a:d /s ^| FIND /I "%JOB%"`) DO (
 FOR /R %%F IN (%%A) DO (
  COPY /Y "%%~fF" "%OF%"
 )
)
POPD

It basically locates each subdirectory of ArchiveFolder that includes the JobName in it, then digs into each one that it finds to copy the files out of them.

EDIT2:

Added NET USE to access your network share to perform tasks on the files. If your local machine already has the UNC assigned to a driveletter, you can remove the NET USE command line and change Z: to the assigned driveletter.

雅心素梦 2024-12-13 16:54:27
@ECHO OFF
FOR /R %%v IN (job*.xml) DO COPY "%%v" c:\out\
@ECHO OFF
FOR /R %%v IN (job*.xml) DO COPY "%%v" c:\out\
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文