2

I have many files that are stored in a deep hierarchy like this:

F:\Files\FX\Water\APX\Build\Setup\myfile.mp4
F:\Files\FX\1\2\3\4\otherfile.mp4

and I want to copy them into another drive that has one more nested layer but at the lower folder level:

F:\Files\FX\Water\MICROSOFT\APX\Build\Setup\myfile.mp4
F:\Files\FX\1\MICROSOFT\2\3\4\otherfile.mp4

So as you can see, I am not able to do a simple copy paste. Is there a command I can run on cmd or PowerShell that will let me copy all the files at once, overriding the target files?

I am on Windows 10 Pro.

  • I've offered a solution that should work based on the info you provided. Awaiting feedback. – Keith Miller Oct 6 at 4:26
0

So as you can see, I am not able to do a simple copy paste. Is there a command I can run on cmd or powershell or even an app that will let me copy all the files at once, overriding the target files?

Perhaps I am not fully understanding your question, but you should be able to do something along the lines of:

robocopy F:\Files\FX\Water\APX\Build\Setup F:\Files\FX\Water\MICROSOFT\APX\Build\Setup *.*

The destination directory doesn't need to exist. robocopy should be available on Windows Vista or later and has options to copy subdirectories (as needed).

  • *.* is redundant as it is the default behaviour in Robocopy, so including it won't do anything. – Mr Ethernet Oct 5 at 11:22
  • Understood. In this case, I intended *.* to show where files might go (rather than e.g C:\some\path\*.*). Probably should have been clearer. – Anaksunaman Oct 5 at 11:26
  • Thanks a lot but is there a way to use wildcards for Water, APX and Build as they change in the source and target the same way. So I need them to be * in the source and the target. – Radiation4TheNation Oct 5 at 11:27
  • @Radiation4TheNation RoboCopy does support wildcards, but I'm not sure if it does for directories in a path. If it doesn't, a simple cmd script would likely work, else this would work for everything but the Water directory: robocopy F:\Files\FX\Water\ F:\Files\FX\Water\MICROSOFT /e. I would also recommend the following parameters: /Log:%UserProfile%\RoboCopy.log || /Log+:%UserProfile%\RoboCopy.log (the + appends, whereas w/o it, the log will be overwritten upon a new execution... if running within a PS terminal, append cmd /c in front of command). – JW0914 Oct 5 at 12:00
  • Offhand, I don't believe robocopy supports wildcards for folders (could be wrong, though). But to JW0914's comment, some simple scripting is the solution I would be leaning towards. – Anaksunaman Oct 5 at 12:10
0

There are several ways to do this : 1) In Powershell

Copy-Item -Path <SourcePath> -Destination <DestinationPath> # -force if already existing at the target

2) With Cmd

Copy <SourcePath> <DestinationPath> 

Note that the file inherits permissions from the parent folder to the target.

0

You can do this easily using Robocopy.

  1. Open a Command Prompt window
  2. Run the following command:

robocopy /e f:\files\fx\water\apx\build\setup f:\files\fx\water\microsoft\apx\build\setup

  • /e must be used in order to include any subfolders (or empty subfolders) that exist in your source folder. Without this switch, Robocopy will only copy files and will ignore subfolders. It's usually best to include it.
  • there is no need to add "." as Robocopy copies all files by default, so that would be redundant.

Update:

The OP has updated his question to include a requirement for source path folder wildcarding.

Source path folder wildcarding isn't supported in Robocopy, as the only wildcards it supports are those used either in file names or file extensions.

As a result of this limitation, Robocopy cannot help the OP here. An answer using an alternative scripting solution is required.

  • Thanks a lot but is there a way to use wildcards for Water, APX and Build as they change in the source and target the same way. So I need them to be * in the source and the target. – Radiation4TheNation Oct 5 at 11:27
  • Can you clarify what the paths would be for one of the other examples? For example water? Is the source path: f:\files\fx\water? What about the destination path? – Mr Ethernet Oct 5 at 11:32
  • Hi I actually updated the question. But basically anything under FX, i.e. water, APX and Build can change, but whatever the change i.e. Fire/BPX/Generic will be the same in destrination, just that the destination always have MICROSOFT right under FX/FOLDER/MICROSOFT – Radiation4TheNation Oct 5 at 11:36
  • It's a bit more confusing now because of these changing paths. When does the path change? How often? Randomly? Will it revert to the original path later? Does the destination path change too? The hardest part of this question is just trying to understand exactly what the situation is! We need a little more information in the question in order to be able to come up with a good solution. – Mr Ethernet Oct 5 at 11:51
  • To explain it simpler I need this: copy F:/Files/FX/*/*/*/*/*.mp4 F:/Files/FX/*/MICROSOFT/*/*/*/*.mp4 – Radiation4TheNation Oct 5 at 12:13
0

This can be done in PowerShell. But we may need some clarification.

Does this command list the files we want copied?

gci F:\files\Fx *.mp4 -recurse | select fullname

If not, you need to provide the detail that will allow us to select the desired files.

Once you have that right, you construct your new path:

gci F:\files\Fx *.mp4 -recurse | Foreach{
   $folders = $_.Fullname.split('\')
   $NewPath = $Folders[0..3] + 'Microsoft' + $Folders[4..($Folders.Count-1)]
   $NewPath -join '\'
}

If those paths look right, add the Copy-Item cmdlet:

gci F:\files\Fx *.mp4 -recurse | Foreach{
   $folders = $_.Fullname.split('\')
   $NewPath = $Folders[0..3] + 'Microsoft' + $Folders[4..($Folders.Count-1)]
   $NewPath = $NewPath -join '\'
   Copy-Item $_.FullName $NewPath
}

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.