批量文件重命名–从列表中插入文本(Python 或 Java 中)
我正在完成名片制作流程(excel > xml > indesign > 单页 pdf),我想在文件名中插入员工的姓名。
我现在拥有的:
BusinessCard_01_Blue.pdf
BusinessCard_02_Blue.pdf
BusinessCard_03_Blue.pdf (they are gonna go up to the hundreds)
我需要的(我可以使用正则表达式轻松操作名单):
BusinessCard_01_CarlosJorgeSantos_Blue.pdf
BusinessCard_02_TaniaMartins_Blue.pdf
BusinessCard_03_MarciaLima_Blue.pdf
我是一个 Java 和 Python 幼儿。我已阅读相关问题,在 Automator (Mac) 和 Name Mangler 中尝试过此操作,但无法使其工作。
提前致谢, 格斯
I'm finishing a business card production flow (excel > xml > indesign > single page pdfs) and I would like to insert the employees' names in the filenames.
What I have now:
BusinessCard_01_Blue.pdf
BusinessCard_02_Blue.pdf
BusinessCard_03_Blue.pdf (they are gonna go up to the hundreds)
What I need (I can manipulate the name list with regex easily):
BusinessCard_01_CarlosJorgeSantos_Blue.pdf
BusinessCard_02_TaniaMartins_Blue.pdf
BusinessCard_03_MarciaLima_Blue.pdf
I'm a Java and Python toddler. I've read the related questions, tried this in Automator (Mac) and Name Mangler, but couldn't get it to work.
Thanks in advance,
Gus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设你有一个地图,可以在其中查看正确的名称,你可以在 Java 中执行类似的操作:
并将
getNameFor
定义为:在地图中,你将拥有关联:
这有意义吗? ?
Granted you have a map where to look at the right name you could do something like this in Java:
And define the
getNameFor
to something like:In the map you'll have the associations:
Does it make sense?
在 Python 中(已测试):
编辑:现在仅更改那些尚未更改的文件。
如果您想要自动构建
employees
字典的东西,请告诉我。In Python (tested):
EDIT: This now alters only those files that have not yet been altered.
Let me know if you want something that will build the the
employees
dictionary automatically.如果你有一个与文件生成顺序相同的名称列表,在 Python 中它就像这个未经测试的片段:
If you have a list of names in the same order the files are produced, in Python it goes like this untested fragment:
Python:
假设您已经实现了命名逻辑:
当然,您需要编写一个函数
new_name
,它接受字符串"BusinessCard_01_Blue.pdf"
并返回该字符串“BusinessCard_01_CarlosJorgeSantos_Blue.pdf”
。Python:
Assuming you have implemented the naming logic already:
You will, of course, need to write a function
new_name
which takes the string"BusinessCard_01_Blue.pdf"
and returns the string"BusinessCard_01_CarlosJorgeSantos_Blue.pdf"
.