How to use the mv command in Python with subprocess

后端 未结 4 2123
天命终不由人
天命终不由人 2021-02-19 10:39

I have a lot of files in /home/somedir/subdir/ and I\'m trying to move them all up to /home/somedir programmatically.

right now I have this:

subprocess.c         


        
4条回答
  •  天命终不由人
    2021-02-19 11:21

    You are using shell globbing *, and expecting the mv command to know what it means. You can get the same error from a command shell this way:

    $ mv 'somedir/subdir/*' ...

    Notice the quotes. The shell usually does glob-matching on * for you, but commands don't do that on their command lines; not even a shell does. There is a C library function called fnmatch that does shell-style globbing for you, which every programming language more or less copies. It might even have the same name in Python. Or it might have the word "glob" in it; I don't remember.

提交回复
热议问题