0

i'm looking for a sollution to copy multiple files from different folders to 1 folder.

What I have is that I need to copy files from

c:\Customers\folderA\folderB\files

copy to e:\FolderB\files

The problem is that the "Customers" everytime is different. Also FolderA is different. Only FolderB is the same.

I've tried it with robocopy or with copy. But I always have to fill in the Customers name.

Can some one help me?

So I tried it into powershell

and i came to

Copy-Item -Path C:\customer -Recurse -filter *.xls -Destination e:\folderB -Force

only with this i filter to files and all the folders al copied. And i only want the files in it.

ptjuh
  • 11
  • 1
  • 4
  • Here is probably what you are looking for: http://stackoverflow.com/questions/21750311/get-childitem-and-copy-item-explanation – Cyrill Nov 03 '15 at 10:51
  • thats a powershell command. I don't know anything about powershell so i want do it with CMD – ptjuh Nov 03 '15 at 11:01
  • 1
    That's probably the worst attitude to have when trying to resolve IT problems. – CIA Nov 04 '15 at 03:20
  • Sorry , it was the worst attitude. My apollogies.... Thanks for the command Cyrill. Maybe its beter to try it on more way's the one wanted. I will see in to the powershell command to – ptjuh Nov 05 '15 at 07:49

1 Answers1

0

You can use the FOR /D command to loop through the directories in a path:

FOR /D %%I IN (C:\Customers\*) DO (
REM %%I is "C:\Customers\FolderA", etc.
    robocopy.exe /E "%%I\FolderB\files" "C:\FolderB\files"
)

Let's assume the directory C:\Customers contains:

  • A. Datum Corporation
  • AdventureWorks Cycles
  • Alpine Ski House
  • Awesome Computers
  • Baldwin Museum of Science
  • Blue Yonder Airlines

If we run this simple command script:

FOR /D %%I IN (C:\Customers\*) DO (
    ECHO %%I
)

We get this output:

C:\Customers\A. Datum Corporation
C:\Customers\AdventureWorks Cycles
C:\Customers\Alpine Ski House
C:\Customers\Awesome Computers
C:\Customers\Baldwin Museum of Science
C:\Customers\Blue Yonder Airlines

So taking that a step further, this command script:

FOR /D %%I IN (C:\Customers\*) DO (
    robocopy.exe /E "%%I\FolderB\files" "C:\FolderB\files"
)

Would run the following commands in sequence:

robocopy.exe /E "C:\Customers\A. Datum Corporation" "C:\FolderB\files"
robocopy.exe /E "C:\Customers\AdventureWorks Cycles" "C:\FolderB\files"
robocopy.exe /E "C:\Customers\Alpine Ski House" "C:\FolderB\files"
robocopy.exe /E "C:\Customers\Awesome Computers" "C:\FolderB\files"
robocopy.exe /E "C:\Customers\Baldwin Museum of Science" "C:\FolderB\files"
robocopy.exe /E "C:\Customers\Blue Yonder Airlines" "C:\FolderB\files"

The output, of course, would be the result of each robocopy command.

ghaberek
  • 111
  • 5
  • thanks for the input, but the customer folder contains more than 100+ folders so to set them al its just almost like handwork. or do I interpreteri the format wrong? – ptjuh Nov 05 '15 at 11:02
  • The FOR loop should do what you're asking. I updated my answer with a couple examples to show how it works. – ghaberek Nov 06 '15 at 01:13