मैं एक बिन फ़ोल्डर (OutputDir/बिन) कुछ फ़ाइलें जो OutputDir में रहने के अलावा में सभी निर्माण उत्पादन फ़ाइलों और फ़ोल्डरों को कॉपी करने की कोशिश कर रहा हूँ ले जाएँ। बिन फ़ोल्डर कभी नहीं हटाया जाएगा।Powershell: फ़ाइलें रिकर्सिवली
प्रारंभिक शर्त:
Output
config.log4net
file1.txt
file2.txt
file3.dll
ProjectXXX.exe
en
foo.txt
fr
foo.txt
de
foo.txt
लक्ष्य:
Output
Bin
file1.txt
file2.txt
file3.dll
en
foo.txt
fr
foo.txt
de
foo.txt
config.log4net
ProjectXXX.exe
मेरे पहली कोशिश:
$binaries = $args[0]
$binFolderName = "bin"
$binFolderPath = Join-Path $binaries $binFolderName
New-Item $binFolderPath -ItemType Directory
Get-Childitem -Path $binaries | ? {$_.Name -notlike "ProjectXXX.*" -and $_.Name -ne "config.log4net" -and $_.Name -ne $binFolderName } | Move-Item -Destination $binFolderPath
यह कोई करता है टी काम, क्योंकि Move-Item
फ़ोल्डर को ओवरराइट करने में सक्षम नहीं है।
मेरी दूसरी कोशिश:
function MoveItemsInDirectory {
param([Parameter(Mandatory=$true, Position=0)][System.String]$SourceDirectoryPath,
[Parameter(Mandatory=$true, Position=1)][System.String]$DestinationDirectoryPath,
[Parameter(Mandatory=$false, Position=2)][System.Array]$ExcludeFiles)
Get-ChildItem -Path $SourceDirectoryPath -Exclude $ExcludeFiles | %{
if ($_ -is [System.IO.FileInfo]) {
$newFilePath = Join-Path $DestinationDirectoryPath $_.Name
xcopy $_.FullName $newFilePath /Y
Remove-Item $_ -Force -Confirm:$false
}
else
{
$folderName = $_.Name
$folderPath = Join-Path $DestinationDirectoryPath $folderName
MoveItemsInDirectory -SourceDirectoryPath $_.FullName -DestinationDirectoryPath $folderPath -ExcludeFiles $ExcludeFiles
Remove-Item $_ -Force -Confirm:$false
}
}
}
$binaries = $args[0]
$binFolderName = "bin"
$binFolderPath = Join-Path $binaries $binFolderName
$excludeFiles = @("ProjectXXX.*", "config.log4net", $binFolderName)
MoveItemsInDirectory $binaries $binFolderPath $excludeFiles
वहाँ PowerShell का उपयोग कर एक और अधिक आसान तरीका में रिकर्सिवली फ़ाइलों को ले के किसी भी वैकल्पिक रास्ता नहीं है?
आप इसे खत्म करना चाहते हैं क्योंकि इससे आपको आवश्यक उत्तर प्राप्त करने में मदद मिलेगी। –