0
  1. I have a folder (Students located in server A) containing 800 files, each has a unique identifier in the first 6 characters of the filename (e.g.Y9L-01_xxx.xlsx; Y9L-02_xxx.xlsx; Y9L-03_xxx.xlsx etc).

  2. I have folders with sub folders where I would like to transfer the files. These folders are located in server B.

  3. Each folder in number 2 above contains the same 6 character unique identifier of the filename at the beginning of the folder name (Y9L-01; Y9L-02; Y9L-03). There is a sub folder called 2014_Hockey under the folders Y9L-01; Y9L-02; Y9L-03;

  4. I would like to transfer the files from the "Students" folder described in 1 above to each of the 2014_Hockey folder that is located under Y9L-01; T9L-02; Y9L-03 etc described in 2 and 3 above.

Effectively, I would like the script to match the first 6 characters of the file name with the first 6 characters of the folder names described in #3 and then move the file to the 2014_Hockey folder under that folder.

Example: The .xslx file in \Students\Y9L-01_HockeyChampionship.xslx located in server A to move to Y9L-01\2014_Hockey located in server B

How do I do this?

Thanks

Regards Rauri

0

This should be easily doable with PowerShell. I haven't tested this myself yet, so you should try it on some sample data before using it on your real files.

Get-ChildItem '\\ServerA\Students' | ForEach-Object {$NewFolder = $_.Name.Substring(0,6); Move-Item $_ "\\ServerB\$NewFolder\2014_Hockey"}

You may see unexpected results if some of the files in \\ServerA\Students don't match the naming convention you've specified.

This will, for example, do the following:

\\ServerA\Students\Y9L-01_HockeyChampionship.xlsx
will be moved to
\\ServerB\Y9L-01\2014_Hockey\Y9L-01_HockeyChampoinship.xlsx

If you need to only move the Excel files, you'll need to filter the rest out by adding in Where-Object like this:

Get-ChildItem '\\ServerA\Students' | Where-Object {$_.Extension -eq '.xlsx'} | ForEach-Object {$NewFolder = $_.Name.Substring(0,6); Move-Item $_ "\\ServerB\$NewFolder\2014_Hockey"}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.