【问题标题】:Batch file to create file structure according to another structure批处理文件根据另一个结构创建文件结构
【发布时间】:2014-01-22 13:56:36
【问题描述】:

好吧,我需要制作一个脚本(VBS、Batch 等),它将采用现有的文件结构,复制它并在每个文件夹的新结构中创建特定的子文件夹。示例

Current structure :
Folder 1
Folder 2
Folder 3

脚本将采用这些,并在另一个文件夹中重新创建以下结构:

Folder 1
*-- Folder X
*-- Folder Y
*-- Folder Z
Folder 2
*-- Folder X
*-- Folder Y
*-- Folder Z

【问题讨论】:

  • 这个问题毫无意义。开始和结束文件夹结构与问题文本的正文不一致。您说您正在复制现有结构,但您的结果缺少任何此类复制。

标签: file batch-file vbscript structure


【解决方案1】:

这个 powershell 脚本应该做你想做的事:

$source_dir="c:\temp\structure"
$destination="c:\desination"

$model=ls $source_dir -dir
$model |%{ 
    $name=$_.name
    new-item -itemType directory -path $destination\$name
    ("X","Y","Z")|% { new-item -itemType directory -path $destination\$name\$_}

}

【讨论】:

    【解决方案2】:
    @echo off
        set "source=c:\source"
        set "target=c:\target"
        for /d %%f in ("%source%\*") do for %%t in ("X" "Y" "Z") do (
            echo md "%target%\%%~nxf\%%~t" 2>nul
        )
    

    目录创建仅回显到控制台。如果输出正确,请在md之前删除echo命令

    【讨论】:

      【解决方案3】:

      VBScript 解决方案:

      Set fso = CreateObject("Scripting.FileSystemObject")
      
      src = "C:\foo"
      dst = "C:\bar"
      
      newFolders = Array("X", "Y", "Z")
      
      For Each sf In fso.GetFolder(src).SubFolders
        dir = fso.BuildPath(dst, sf.Name)
        fso.CreateFolder dir
        For n In newFolders
          fso.CreateFolder fso.BuildPath(dir, n)
        Next
      Next
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多