简体   繁体   English

创建子文件夹结构

[英]Creating a sub-folder structure

Looking for some advice on how to use PowerShell (or some other means) to create some folders.寻求有关如何使用 PowerShell(或其他方式)创建一些文件夹的建议。

I have a list of around 120 products that I've allocated separate folders.我有一份大约 120 种产品的列表,这些产品已分配给单独的文件夹。 (using a CSV to generate the folders) (使用 CSV 生成文件夹)

I want each product folder to have the same subfolder structure.我希望每个产品文件夹都具有相同的子文件夹结构。 As shown below:如下所示:

[Products]
├── [Product 1]
│   ├── [1. Datasheet]
│   │   ├── [1. Current]
│   │   ├── [2. Archived]
│   │   ├── [3. Legacy]
│   │   ├── [4. Draft]
│   │   └── [5. Resources]
│   ├── [2. Images]
│   ├── [3. Brochures]
│   ├── [4. Manuals]
│   └── [5. Software]
│
├── [Product 2]
│   ├── [1. Datasheet]
│   │   ├── [1. Current]
│   │   ├── [2. Archived]
│   │   ├── [3. Legacy]
│   │   ├── [4. Draft]
│   │   └── [5. Resources]
│   ├── [2. Images]
│   ├── [3. Brochures]
│   ├── [4. Manuals]
│   └── [5. Software]
:
:

Essentially the first layer of subfolders in each would be:基本上每个子文件夹的第一层将是:

[1. Datasheet] [1. Datasheet] , [2. Images] [1. Datasheet][2. Images] [2. Images] , [3. Brochures] [2. Images][3. Brochures] [3. Brochures] , [4. Manuals] [3. Brochures] , [4. Manuals] [4. Manuals] , [5. Software] [4. Manuals] , [5. Software] [5. Software]

Inside each of these would be the following:在每一个内部将是以下内容:

[1.Current] , [2.Archived] , [3. Legacy] [1.Current] [2.Archived] , [3. Legacy] [2.Archived] , [3. Legacy] [3. Legacy] , [4. Draft] [3. Legacy][4. Draft] [4. Draft] , [5. Resources] [4. Draft][5. Resources] [5. Resources]

I don't mind doing this in stages, it's just I don't know where to begin.我不介意分阶段做这件事,只是我不知道从哪里开始。

This could work:这可以工作:

$workingdir = 'c:\temp'

$products = Get-Content c:\temp\listofproducts.txt

$rootfolders = @(
    'Datasheet'
    'Images'
    'Brochures'
    'Manuals'
    'Software'
)

$subfolders = @(
    'Current'
    'Archived'
    'Legacy'
    'Draft'
    'Resources'
)

foreach ($product in $products) 
{
    $rootcount = 0
    foreach ($root in $rootfolders) 
    {
        $rootcount++
        $subcount = 0
        foreach ($sub in $subfolders) 
        {
            $subcount++
            mkdir (Join-Path $workingdir ("$product\$rootcount. $root\$subcount. $sub"))
        }
    }
}

or you could just create the first product folder then copy and paste it then rename the product或者您可以创建第一个产品文件夹,然后复制并粘贴它,然后重命名产品

Thanks for the input.感谢您的投入。

Managed to find a strategy that worked for me, so will share it in case it's of use to anyone else like me.设法找到了一个对我有用的策略,所以会分享它,以防它对像我这样的其他人有用。

Used a combination of the following 3 bits of code to achieve what I needed:使用以下 3 位代码的组合来实现我所需要的:

# Create Folders from CSV

$folder = "Z:\Products\"
$name = Import-Csv Z:\Products\names.csv
Foreach ($line in $name)
{
    New-Item -path $folder -Name $line.Name -Type Directory
}

This above code allowed me to make a big list of folders from a CSV list made in Excel.上面的代码允许我从 Excel 中创建的 CSV 列表中创建一个大的文件夹列表。

# Add a Subfolder

foreach($folder in (gci 'Z:\Products' -directory)){
    new-item -ItemType directory -Path ($folder.fullname+"\subfolder")
}

This above code let me populate the list of folders with subfolders.上面的代码让我用子文件夹填充文件夹列表。 I added them one at a time.我一次添加一个。

# Copy a file to folder

$folders = Get-ChildItem Z:\Products
foreach ($folder in $folders.name){
Copy-Item -Path "Z:\Datasheet\changelog.txt" -Destination "Z:\Products\$folder" -Recurse
}

This above code allowed me to copy items to subfolder locations.上面的代码允许我将项目复制到子文件夹位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Powershell将文件夹结构中的文件复制到其各自的子文件夹 - Copy files in a folder structure to their respective sub-folder with Powershell 具有最新写访问权限的输出子文件夹 - Output sub-folder with the latest write access 在每个文件夹中创建一个子文件夹然后将所有文件和文件夹移动到该子文件夹中的代码是什么? - What is a code to create a sub-folder in each folder and then move all the files and folders into that sub-folder? 将子文件夹名称导出为路径,并为不同位置的每个父子文件夹创建 csv - Export sub-folder name as path and create a csv for each parent sub-folder in a different location 扫描Powershell中每个文件夹的特定子文件夹 - Scan specific sub-folder of every folder in powershell 在PowerShell中新子文件夹中检测CSV文件 - Detecting csv files in newly sub-folder in PowerShell 将文件从子文件夹复制到父文件夹并使用父文件夹名称重命名文件 - Copy file from sub-folder to parent folder and rename the file with parent folder name 如何使用powershell从文件夹的根目录中仅删除子文件夹和子文件夹内容而不是单个文件 - How to delete only the sub-folders and sub-folder contents but not individual files from the root of a folder using powershell Cmd - 使用命令行在子文件夹中创建文件的最简单方法 - Cmd - easiest way to create a file in sub-folder using command line 使用 powershell 将子文件夹内容上移一级; 不同的父文件夹 - Using powershell to move sub-folder contents up one level; different parent folders
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM