VSCODE批处理重命名文件使用解析文件名

发布于 2025-02-13 22:27:21 字数 254 浏览 0 评论 0原文

我有一个文件夹的“日期+索引”'PDF文件,我需要重新订购日期格式。 当前格式ddmmyyy_index.pdf。示例:01012006_1.pdf。 我希望格式为yyyy_mm_mm_dd-index.pdf。结果示例2006_01_01-1.pdf。 第一个障碍是将文件名解析并重新订购。可选的任务是占用“ 0”开头的所有几个月和几天,以删除“ 0”,因此最终结果将是2006_1_1_1-1.pdf。

我想使用VSCODE来执行此操作,但是任何常见的脚本类型都是可以接受的。

I have a folder of ''date+index'' pdf files that I need to re-order the date format.
Current format ddmmyyyy_index.pdf. Example: 01012006_1.pdf.
I want the format to be yyyy_mm_dd-index.pdf. Result example 2006_01_01-1.pdf.
The first hurdle is getting the file name parsed and re-ordered. The optional task is to take all months and days that begin with '0' to drop the '0', so the final result would be 2006_1_1-1.pdf.

I would like to use vscode to do this, but any common script type is acceptable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你的占有欲 2025-02-20 22:27:21

我不确定使用VS代码重新排序日期格式是什么意思;但是,您可以使用TypeScript进行:

const str: string = '01012006_1.pdf'
const day: string = str.match(/.{1,2}/g)[0]
const month: string = str.match(/.{1,2}/g)[1].match(/.{1,2}/g)[0]
const year: string = str.match(/.{1,4}/g)[1]
const index: string = str.split('_')[1]

result = year + '_' + month.replace('0', '') + '_' + day.replace('0', '') + '-' + index + '.pdf'

I am not sure what you mean by using VS Code to re-order the date format; however, you can use TypeScript to do so:

const str: string = '01012006_1.pdf'
const day: string = str.match(/.{1,2}/g)[0]
const month: string = str.match(/.{1,2}/g)[1].match(/.{1,2}/g)[0]
const year: string = str.match(/.{1,4}/g)[1]
const index: string = str.split('_')[1]

result = year + '_' + month.replace('0', '') + '_' + day.replace('0', '') + '-' + index + '.pdf'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文