连接String和Int以形成文件名前缀 [英] Concatenate String and Int to form file name prefix

查看:90
本文介绍了连接String和Int以形成文件名前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与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以形成文件名前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆