如何将单个文件复制到目录中的所有子文件夹? [英] How Do I Copy A Single File To All Subfolders In A Directory?

查看:113
本文介绍了如何将单个文件复制到目录中的所有子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

复制

C:\ TempC\ABSS \d2kwut60.dll



进入任何子文件夹

C:\Program Files\Java \ all子文件夹



如何在PowerShell中执行此操作?



代码如下所示:

#PowerShell的New-Item创建一个文件夹

$ Location =C:\ TempC \

New-Item -Path $ Location -NameABSS-ItemTypedirectory



#Invoke-Item $ Location

$ targetdirectory =C:\ TempC \ ABSS

$ sourcedirectory =\\\\\ Software \ABSS \ ABSS Files \



#错误处理





#Copying项目从源到新创建的目标目录在共享位置的本地机器上

if(!(Test-Path -path $ targetdirectory)){New-Item $ targetdirectory -Type Directory}

Copy-Item - 路径$ sourcedirectory \d2kwut60.dll -Destination $ t argetdirectory

Copy-Item -Path $ sourcedirectory \ _jacob.dll -Destination $ targetdirectory

Copy-Item -Path $ sourcedirectory\JNIsharedStubs.dll -Destination $ targetdirectory

复制项目-Path $ sourcedirectory \webutil.properties -Destination $ targetdirectory



复制项目$ targetdirectory \d2kwut60.dll C :\ Program Files \ Java

解决方案

Location =C:\ TempC \

New-Item -Path


Location -NameABSS-ItemTypedirectory



#Invoke-Item


< blockquote>位置


copy
C:\TempC\ABSS\d2kwut60.dll

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\webutil.properties -Destination $targetdirectory

Copy-Item $targetdirectory\d2kwut60.dll C:\Program Files\Java

解决方案

Location = "C:\TempC\"
New-Item -Path


Location -Name "ABSS" -ItemType "directory"

#Invoke-Item


Location


这篇关于如何将单个文件复制到目录中的所有子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆