0

プレフィックスと連結するとドキュメントのタイトルを与える増分 6 桁の値と組み合わせて事前に提供されたプレフィックスを使用して、フォルダー内のファイルの名前を変更するスクリプトを作成しています。

提供されたフォルダーからファイルリストを反復処理し、最初に提供された番号が最初の増分であるたびに増分番号を増分するプレフィックスで各ファイル名を変更するスクリプトが必要です。

私は近くにいますが、いくつかのエラーが発生しており、どこが間違っているのかわかりません。お知らせ下さい。

Write-host "Please enter prefix:"
[String]$strPrefix = read-host

Write-host "Please enter incrimental value:"
[int]$intInc = read-host

Write-host "Please enter Files folder:"
[String]$strFiles =  "C:\scripts\files"
#$items = Get-ChildItem -Path $strFiles
$items = $strFiles

$intInc

#for each file in $strFiles
foreach ($file in $items )
{
    $newName = $strPrefix + ('0' * (6 - $intInc.ToSTring().Length)) + ($intInc++).ToString()

    if ($extOnly.length -eq 0) 
    {
        Rename-Item New-Name{$file -replace  '$newName'}
    }
    else 
    {
        Write-host "NewName $newName$extOnly"

        Rename-Item New-Name{$file -replace '$newName$extOnly'}
    } #end else

    $file

}#end for

私は近くにいると思いますが、何かが倒れているだけです

4

1 に答える 1

0
Write-host "Please enter prefix:"
[String]$strPrefix = read-host

Write-host "Please enter incrimental value:"
[int]$intInc = read-host

Write-host "Please enter Files folder:"
[String]$strFiles =  "C:\temp\files"

$files = get-childitem $strFiles -recurse

ForEach ($file in $files) {
$intIncPadded = "{0:D6}" -f $intInc
$newName = "$strPrefix$intIncPadded" + $file.Extension
Rename-Item $file.FullName $newName 
$intInc = $intInc + 1
}
于 2011-08-12T13:33:59.833 に答える