将目录中的所有文件重命名为与目录相同
我有一个名为“tokens”的文件夹。在这个文件夹中,我还有其他几个文件夹,称为“guard”、“noble”、“assassin”等。这些文件夹中是具有不同名称和文件格式的图像文件。
我想遍历“令牌”中的所有文件夹和文件,并将每个文件重命名为它所在的任何目录,并附加一个数字。因此,“guard”文件夹中的文件将命名为“guard0001.jpg”,下一个文件将命名为“guard0002.png”。
I have a folder called "tokens". In this folder, I have several other folders, called things like "guard", "noble", "assassin", etc. In those folders are image files with varying names and file formats.
I would like to run through the all the folders and files in "tokens", and rename each file to be whatever directory it is in with a number appended to it. So, a file in the "guard" folder would be named "guard0001.jpg", and the next would be "guard0002.png", for instance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然有更好/更快的方法,但这应该可以解决问题。
当您对它产生的输出感到满意时,删除
echo
。There are certainly better/faster approaches but this should do the trick.
Remove the
echo
when you're satisfied with the output it produced.