【问题标题】:In VSCode, how can I replace text with file information?在 VSCode 中,如何将文本替换为文件信息?
【发布时间】:2022-01-13 19:11:21
【问题描述】:

在 VSCode 中,我想用出现该字符串的文件名替换目录中的特定字符串,例如 x。我可以从搜索菜单中执行此操作吗?如果没有,是否有我可以使用的扩展程序?

【问题讨论】:

    标签: regex visual-studio-code


    【解决方案1】:

    您可以使用像这样的简单 python 脚本循环遍历目录,使用正则表达式获取您想要更改的文件,然后将它们更改为您想要的。

    import os
    import re
    from pathlib import Path
    p = Path('C:/Users/user/Pictures')
    
    files = []
    for x in p.iterdir(): 
        a = re.search('.*(jpe?g|png)',str(x))
        if a is not None:
            files.append(a.group())
            old_file_name = a.group()
            new_file_name = newname
            os.rename(old_file_name, new_file_name)
    

    【讨论】:

      猜你喜欢
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      • 2019-10-09
      • 2020-06-27
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 2022-01-23
      相关资源
      最近更新 更多