批处理文件,该文件在路径中创建带有通配符的文件夹 [英] Batch file that creates folder with wildcard in path

查看:87
本文介绍了批处理文件,该文件在路径中创建带有通配符的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个创建文件夹的批处理文件(如果不存在),然后将某个文件复制到该文件夹​​中.到目前为止一切顺利.

I want to write a batch file that creates a folder (if it does not exist) and copies a certain file into that folder. So far so good.

问题在于路径中的一个文件夹有时会略有不同,因此必须使用通配符.

The problem is that one folder in the path varies slightly from time to time, so a wildcard becomes necessary.

以下代码可以正常工作,但显然错过了创建文件夹(报告)的机会.因此,如果文件夹不存在,则它什么也不做.

The following code works just fine but obviously misses to create the folder (Reports). So if the folder is not there, it simply does nothing.

for /r "c:\Users\%USERNAME%\AppData\Local\Packages" &&G in ("LocalState\acn\Reports") do @if exist %%G xcopy /s /i /y c:\temp\Reporting "%%G"

完整路径为: c:\ Users \ FSchneider \ AppData \ Local \ Packages \"WILDCARD" \ LocalState \ acn \ Reports \

有什么主意吗?

推荐答案

  • for 中添加/d 开关,以表明您要查找的是目录,而不是文件
  • 添加 * 并在通配符中省略引号以表明它实际上是通配符
  • 现在不需要如果存在

    • Add /d switch in for to indicate you're looking for a directory, not a file
    • Add * and omit quotes in the wildcard to indicate it's actually a wildcard
    • No need for if exist now

      for /d /r "%LocalAppData%\Packages" %%G in (LocalState\acn.*) do xcopy /s /i /y c:\temp\Reporting "%%G\Reports"
      

    • 这篇关于批处理文件,该文件在路径中创建带有通配符的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆