我如何从一个旧的文件夹结构,新的移动文件? [英] How do I move files from an old folder structure to new?

查看:160
本文介绍了我如何从一个旧的文件夹结构,新的移动文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改我现有的文件夹结构。我这是按以下方式组织的文件树:

I want to modify my existing folder structure. I had a file tree that was organized in the following way:

Client Name
  State/Province
    City
      Order Number

但我已经修改了它由一个连字符分隔的顺序号码前添加一个地址,这样:

But I have modified it to add an address before the order number separated by a hyphen, as such:

Client Name
  State/Province
    City
      Order Number - Address

我创建了一个宏我有这样生成的原始新的文件夹结构,我想这比重命名现有的文件夹更容易。

I created the new folder structure with a macro I had that generated the original, and I figured this was much easier than renaming the existing folders.

所以现在我想的空文件夹上传到我的服务器,但在此之前我这样做,我想借此从所有的旧体制中的文件并把它们放到新的。

So now I want to upload the empty folders to my server, but before I do that I want to take the files from all the old structure and put them into the new one.

简单地说,我试图写一个脚本文件夹名称在原来的层次结构包含原始名称加上地址的新的层次结构相匹配,然后将文件在原来的文件夹中的新副本到同样一个名为结构。

Simply, I am trying to write a script to match the folder name in the original hierarchy to the new hierarchy that contains the original name plus address, and then copy the files in the original folder to the similarly named one in the new structure.

我会怎么做呢? VBA,PowerShell中,批处理命令?我不是很精通PS。

How would I do this? VBA, Powershell, Batch Command? I'm not very well versed in PS.

推荐答案

使用一个的foreach 循环与 GET-ChildItem
拷贝项
测试的路径 PowerShell的的的cmdlet 的:

Use a foreach loop with the Get-ChildItem, Copy-Item, and Test-Path Powershell cmdlets:

#Get all address subfolders
$addr_folders = Get-ChildItem c:\"Client Name"\State/Province\City\ -recurse | Where-Object {$_.PSIsContainer -eq $True}

#Loop through all address subfolders
foreach ($address in $addr_folders)
{
  #Copy contents from existing subfolder path to new folder
  if (Test-Path c:\"Client Name"\State/Province\City\"Order Number"\$address)
    {
   Copy-Item c:\"Client Name"\State/Province\City\"Order Number" c:\"Client Name"\State/Province\City\"Order Number - " $address
    }
}

这篇关于我如何从一个旧的文件夹结构,新的移动文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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