我有幾個帶有重複命名約定的文件,例如,將每個n個文件移動到一個單獨的文件夾中
1*Intro*
2*
3*
…
10*intro*
….
我想將每個模塊移動到一個單獨的文件夾中。所以,我應該從每個*intro*
分開,直到下一個。 另外,我應該注意文件編號和排序。 我想,要做到這一點最簡單的方法是:
1. Get a list of intros.
2. Separate their numbers.
3. Start moving files starting from one number till their smaller than the next one.
$i = 1
Ls *intro* | ft {$_.name -replace '\D.*', ''}
// The reason for .* is that the files are `mp4`.
Ls * | ? {$_.name -match '[^firstNumber-SecondNumber-1]'} | move-item -literalpath {$_.fullname} -destination $path + $i++ + '/' +{$_.name}
所以最後的命令應該是這樣的:
Ls *intro* | % { ls * | ? {…} | move-item … }
或者,也許move-item
本身可以做篩選工作。
正則表達式不起作用,我沒有足夠的Powershell知識來寫更好的東西。你能想到任何腳本來做到這一點嗎?另外,我應該如何允許move-item
創建文件夾?
如果有人能以更好的標題編輯此帖子,我將非常感激。
你的文件實際上叫什麼名字? 「*」不是有效的文件名字符。 –
它是任何可能角色的佔位符!通常只是按字母順序。 – Akbari