0

I have the following structure

- folder1
 - file1
 - folder2
   - file2
 - folder3
   - file3
   - file4
   - file5
- folder4
 - file6
 - folder5
   - file7
 - folder5
   - file8

I am trying to copy all the file and the folders to a different directory but what happens is that the folders (folder 1, 2, 3) are copied; within folder 3 are all the corresponding files (file3, file4, and file5) but file1 and file2 which files in folder 1 and folder 2 are left out in the copy.

Below is the powershell code snippet i use:

Copy-Item -Path c:\folder1\folder2\folder3\* -Destination d:\ -Recurse -Verbose

6
  • you need to quote a path with spaces: "c:\folder 1\folder 2\folder 3\*". To rephrase, are you looking to copy everything within "Folder 1" to "*d:*"? Commented Mar 30, 2022 at 13:51
  • why do you expect file1 & file2 to be copied? they are NOT in the specified source dir ... [frown] Commented Mar 30, 2022 at 14:22
  • I updated the question and removed the spaces, sorry for the confusion. I am looking to copy from level 1 (folder1) till the contents of folder3 to d: Commented Mar 30, 2022 at 14:23
  • should -Recurse parameter not cause file1 & file2 to be copied since they are along the path/level of folder3 ? Commented Mar 30, 2022 at 14:34
  • @floki91, -Recurse starts working at c:\folder1\folder2\folder3\ and gets everything below that. If you want everything below folder1, then try c:\folder1\* instead. Commented Mar 30, 2022 at 14:39

1 Answer 1

0

This was what had worked for me - it maybe dirty but it works;

I iterated through the paths copied the files i needed as a complete path into the new location.

The code is unfortunately a combination of groovy and powershell

for(i in pathArray ) { if (i.toString() != "jobs") { . . . def copySpec = powershell(returnStdout: true, script: """ Get-ChildItem '${JENKINS_HOME}\\jobs\\${newPath}*' -Filter *.xml | Copy-Item -Destination ${remoteFolder}${newPath} -Force -PassThru -verbose """)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.