devからルートフォルダにファイルをコピーした後、ファイルの拡張子などを変更するpowershellスクリプトがあります。私はすでに正常にファイルをコピーします。しかし、私は、すべてのサブフォルダに適用される-Recurse(devフォルダを除外したい)を使用するか、コードをeootフォルダにのみ適用することの間にこだわっています。Powershell -Recurseパラメータ。特定のサブディレクトリを除外する方法
CODE:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "$w = $args[0];foreach ($file in Get-ChildItem -Recurse -Path "$w" -Exclude *.bat, *.txt, *.png, *.jpg, *.jpeg, *.gif, *.mp3, *.mp4, dev\\*) {"$w+$file";(Get-Content $w$file).replace('dev/', '') | Set-Content "$w$file";(Get-Content $w$file).replace('.min.js', '.minjs') | Set-Content "$w$file";(Get-Content $w$file).replace('.json', '.xson') | Set-Content "$w$file";(Get-Content $w$file).replace('https://www.google-analytics.com/analytics.js', '/httpswgacanalyticsjs/') | Set-Content "$w$file";(Get-Content $w$file).replace('.js', '.min.js') | Set-Content "$w$file";(Get-Content $w$file).replace('.minjs', '.min.js') | Set-Content "$w$file";(Get-Content $w$file).replace('.xson', '.json') | Set-Content "$w$file";(Get-Content $w$file).replace('/httpswgacanalyticsjs/', 'https://www.google-analytics.com/analytics.js') | Set-Content "$w$file";(Get-Content $w$file).replace('.min.css', '.mincss') | Set-Content "$w$file";(Get-Content $w$file).replace('.css', '.min.css') | Set-Content "$w$file";(Get-Content $w$file).replace('.mincss', '.min.css') | Set-Content "$w$file";};Write-Host ".""" "%path%"
はINPUT:
FOLDER
-> dev
->files
->folders
OUTPUT:
FOLDER
-> dev //exclude
->files //exclude
->folders //exclude
->files //execute code on this
->folders //execute code on this
を試してみてください私はこのPowershellファイルをバッチファイルから起動しますか?彼らは道の中の空間なので、私はそれが動作するように見ることができません。また、どのように引数を入力するのですか? –
powershell -executionPolicy bypass -noexit -file "c:\ temp \ path with space \ test.ps1" "argument" – Esperento57
多くの試行錯誤の後、whereステートメントにはアスタリスクが "* \ dev \ *"なくなっています。助けてくれてありがとう、今は機能している。 –