Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

into any subfolders in
C:\Program Files\Java\all sub folders

How can I perform this in PowerShell?

Code is shown below:
# PowerShell's New-Item creates a folder
$Location = "C:\TempC\"
New-Item -Path $Location -Name "ABSS" -ItemType "directory"

#Invoke-Item $Location
$targetdirectory = "C:\TempC\ABSS"
$sourcedirectory = "\\server2\Software\ABSS\ABSS Files\"

#Error handling

#Copying Items over from source to new created target directory on local machine from the share location
if (!(Test-Path -path $targetdirectory)) {New-Item $targetdirectory -Type Directory}
Copy-Item -Path $sourcedirectory\d2kwut60.dll -Destination $targetdirectory
Copy-Item -Path $sourcedirectory\jacob.dll -Destination $targetdirectory
Copy-Item -Path $sourcedirectory\JNIsharedStubs.dll -Destination $targetdirectory
Copy-Item -Path $sourcedirectory\ -Destination $targetdirectory

Copy-Item $targetdirectory\d2kwut60.dll C:\Program Files\Java
Updated 10-Apr-15 9:35am

Share this answer
[no name] 10-Apr-15 14:54pm    
Based on your answer i used the Copy-Item function.
Copy-Item $targetdirectory\d2kwut60.dll C:\Program Files\Java*
I got returned an error A Positional parameter cannot be found that accepts argument 'Files\Java*'

the file would need to be copied to all the sub folders in the C:\Program Files\Java directory.
Sergey Alexandrovich Kryukov 10-Apr-15 15:18pm    
Then please show your code.
Also, I would note that making multiple copies of the same file sounds like a technology abuse.
[no name] 10-Apr-15 15:35pm    
I am showing the code, if you have a resolve please let me know. Thanks again
Sergey Alexandrovich Kryukov 10-Apr-15 16:06pm    
Better follow my advise I put in Solution 2.
Sergey Alexandrovich Kryukov 10-Apr-15 15:23pm    
5ed, but the whole thing is a bad idea. Please see my comment above.
See also my Solution 2. Unfortunately, not everyone knows that POSIX hard links more typical for *NIX are supported on Windows, but this is so, and a better way to go.
Creating multiple copies of the same file sounds like a bad technology abuse.

In worst case, when some ill-organized structure really needs such multiple copies (one typical application are C/C++ header files used in different places of code), it could be much more appropriate to create POSIX hard links. Windows and NTFS certainly support this POSIX feature. See, for example:

See also:,

Share this answer
[no name] 10-Apr-15 15:42pm    
The reason why I am having it copy to all folders in that directory is because the subfolder after C:\Program Files\Java\"JRE_0.1.8"\ in quotations is a variable folder based on the version of java the user has installed, the files actually need to be copied in the bin folder that comes after the java version specific version. How can i account as the JRE folder being a variable and still reach the bin sub folder in it?
Sergey Alexandrovich Kryukov 10-Apr-15 16:05pm    
All right, create the hard links then. Isn't my solution clear?
If you don't understand it, first read how hard links work.
Maciej Los 10-Apr-15 17:02pm    
Sergey Alexandrovich Kryukov 10-Apr-15 17:27pm    
Thank you, Maciej.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900