【问题标题】:Running python file using batch file使用批处理文件运行python文件
【发布时间】:2014-09-09 08:55:44
【问题描述】:

我在批处理文件中有一个“较小”的问题。我正在从这样的批处理文件中调用 Python“小程序” mybat.bat: FOR %%f IN (*.oldextension) DO (C:\Python27\python.exe myPython.py -i "%%f" -o "%%f.newextension")

它运行良好,但我只想将 -o(output) 文件名重命名/更改为新扩展名并删除旧扩展名。 所以让我们说 file.oldextension --> file.newextension,因为现在它看起来像 file.oldextension --> file.oldextension.newextension

感谢您的帮助:)

【问题讨论】:

    标签: python windows batch-file


    【解决方案1】:
    FOR %%f IN (*.oldextension) DO (
        C:\Python27\python.exe myPython.py -i "%%f" -o "%%~nf.newextension"
    )
    

    其中%%~nf%%f 引用的文件的名称

    【讨论】:

    • 谢谢,它正在工作。我会在 3 分钟内接受它作为一个很好的答案。你为我节省了几个小时 :)
    猜你喜欢
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2012-12-18
    相关资源
    最近更新 更多