Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Script to copy folders matching the name of folders in another directory, searching using a portion of the folder name e.g. first 4 characters.

$
0
0

Good afternoon guys,

I am totally new to PowerShell (only discovered it a week or so ago), or scripting in general for that matter, and therefore am finding it very difficult to tailor scripts I have found on the internet to fit my requirements.

If anyone could help me with this, I’d be extremely grateful;

I have two directories containing a lot of folders>subfolders>files. The first (search – called TEST A) directory is where the main body of files are kept – these are a mix of Excel and Email files which are put into folders named with a unique 4 digit number followed by some text e.g. “1000 – Folder123”.

The second directory (destination – called TEST B) contains an empty folders for each unique 4 digit number e.g. “1000”, “1001”, “1003”, “1004”, “1005” etc.

What I would like to do is run a script which looks up all of the folders in the search folder (TEST A) via the 4 digit number, matches it with the corresponding folder in the destination folder (TEST B), creates a new folder called “COPY TEST” in the matched folder in TEST B, and copies the TEST A folder  – along with any enclosed files – into this new folder called “COPY TEST”. As an example;

TEST A (FOLDER TO BE SEARCHED)                                      TEST B (FOLDERS FOR INFO TO BE COPIED INTO)         

E.g - C:\TEST A\1000 - Folder123                                           E.g - C:\TEST B\1000

"1000 - Folder123"                                                           "1000"

"1001 - Folder446"                                                           "1001"

"1002 - Folder789"                                                           "1002"

"1003 - Folder332"                                                           "1003"

Once the script had been successfully run, the updated TEST B folder would now look something like this:

"C:\TEST B\1000\COPY TEST\1000 - Folder123"

It would also be good if there was something in place to make sure no files were overwritten and that additional copies be made instead.

I hope my explanation is clear enough, although if anyone needs any further clarification I'll do my best to provide this.

Thank you all in advance for your help in this matter.

Regards,

Tom


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>