问题描述
我正在与PowerShell一起为目录中的许多文件创建重命名脚本.
I am working with PowerShell to create a renaming script for a number of files in a directory.
这里有两个问题:
我有一个字符串变量$strPrefix = "ACV-100-"
和一个整数计数器$intInc = 000001
,我希望将计数器$intInc
1-> 2递增,然后将两者连接起来,并按以下格式存储在变量$strCPrefix
中:ACV-100-000002
.
I have a string variable $strPrefix = "ACV-100-"
and an integer counter $intInc = 000001
and I wish to increment the counter $intInc
1 -> 2 and then concatenate the two and store it in a variable $strCPrefix
in the following format: ACV-100-000002
.
我相信$intInc
将需要转换以便在增量完成后进行转换,但是我不确定如何做到这一点.
I believe the $intInc
will need to be cast in order to convert it once incrementing is complete but I am unsure how to do this.
其次,我发现脚本会将000001
显示为1
,将000101
显示为101
,依此类推...我需要显示完整的6位数字,因为这将形成一个文件名.在处理串联之前,如何保留或填充数字?
Secondly, I have found that the script will display 000001
as 1
, 000101
as 101
and so on... I need the full 6 digits to be displayed as this will form a file name. How do I keep or pad the numbers before I process the concatenation?
推荐答案
$intInc = 1
$strCprefix = $strprefix + "{0:000000}" -f $intInc # give ACV-100-000001
希望可以帮助
这篇关于连接String和Int以形成文件名前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!