By toolshed

2012-05-11 18:33:22 8 Comments

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

Client Name
      Order Number

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

Client Name
      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.

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


@Paul Sweatte 2012-07-03 21:41:37

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

Related Questions

Sponsored Content

15 Answered Questions

[SOLVED] How to run multiple .BAT files within a .BAT file

  • 2009-07-09 13:47:14
  • Th3Fix3r
  • 755994 View
  • 635 Score
  • 15 Answer
  • Tags:   batch-file cmd

21 Answered Questions

[SOLVED] How to get the filename without the extension from a path in Python?

  • 2009-03-24 16:41:03
  • Joan Venge
  • 897672 View
  • 818 Score
  • 21 Answer
  • Tags:   python string path

16 Answered Questions

[SOLVED] How can I pass arguments to a batch file?

17 Answered Questions

[SOLVED] Importing modules from parent folder

4 Answered Questions

[SOLVED] How to save file structure to text file?

1 Answered Questions

[SOLVED] move two different file types with same name into a new folder with same name

  • 2016-10-20 19:04:24
  • Ali_R4v3n
  • 67 View
  • 0 Score
  • 1 Answer
  • Tags:   batch-file cmd

0 Answered Questions

1 Answered Questions

[SOLVED] Moving files in windows environment to folders that have part of the file name

  • 2015-03-30 20:26:46
  • Ran Perhar
  • 34 View
  • 2 Score
  • 1 Answer
  • Tags:   batch-file

2 Answered Questions

[SOLVED] Copy files from directory structure but exclude a named folder

2 Answered Questions

[SOLVED] Script to move folders with specific names and characters

  • 2013-08-12 19:26:19
  • Rob
  • 393 View
  • 0 Score
  • 2 Answer
  • Tags:   powershell

Sponsored Content