Using subprocess.Popen (shell=True) with windows folders

前端 未结 1 639
攒了一身酷
攒了一身酷 2021-01-25 06:41

I\'m currently looking at Popen to automate the compression & storage of documents.

For the compression part, I thought of the following Python line:

相关标签:
1条回答
  • 2021-01-25 07:40

    In Windows you should use quotes for file or directory names (if you want to use spaces inside). In Python, you should escape quotes with \ symbol (if you are using strings inside " quotes). Like this:

    "my name is \"Mark\"!"
    

    Or just:

    'my name is "Mark"!'
    

    So this will work as expected:

    subprocess.Popen("WinRAR.exe a -r \"c:\\03. Notes\\AllTexts\" *.txt", shell=True)
    

    As well as:

    subprocess.Popen('WinRAR.exe a -r "c:\\03. Notes\\AllTexts" *.txt', shell=True)
    
    0 讨论(0)
提交回复
热议问题