如果我要创建10个空的.txt
文件,其名称模式为abcd01.txt
,abcd02.txt
,...,abcd10.txt
。如何在CMD / PowerShell中实现?
这是我要实现的目标:
for($i = 0; $i -lt 11; $i++){ New-Item -Path "C:\Users\FOO\Desktop\FOOBAR\abcd",$i,".txt" -ItemType File }
此创建的文件没有任何文件扩展名。 0
,1
,2
,...,10
。
然后我将所有文件重命名为:
Dir -filter * | %{Rename-Item $_ -NewName ("abcd{0}.cpp" -f $nr++)}
是否有单行命令将'n'
空文件扩展为'.xyz'
?
您可以在new-item
中使用的变量中设置前导零的格式:
for($i = 0; $i -lt 11; $i++){
$path = "C:\temp\test{0:00}.txt" -f $i
New-Item -Path $path
}