'moving file with os.system not same as moving from cmd line using same command

I am trying to move a file, using wildcard in file name, to a specific folder from my python script but I get an error which I do not get otherwise when I run the same command from cmd line\ powershell terminal.

python code:

import os
import subprocess

path = '\".\\*.c\" \".\\tag_*\\src\\" -force'
os.system('echo move ' + path)
os.system('move ' + path)

subprocess.run("echo move "+ path , shell=True, check=True)
subprocess.run("move "+ path , shell=True, check=True)

Output:
move ".\*.c" ".\tag_*\src\" -force
The syntax of the command is incorrect.
move ".\*.c" ".\tag_*\src\" -force
The syntax of the command is incorrect.

If I copy the command that is displayed in output terminal using the echo and run that same cmd after pasting in ps terminal, the file is moved successfully.

In powershell terminal, this copies all the c files, to the src folder without any issues, the same is true for any file type (*.h works fine too).

move ".\*.c" ".\tag_*\src\" -force

Could someone please explain why python script fails to do this ? I am able to execute other terminal commands in python script with os.execute, its just that the copy and move commands fail, so far.



Solution 1:[1]

Based on the comments, this solution worked for me:

import shutil

for path in glob('tag_*'):
    for files in glob('*.h'):
       shutil.move('.\\' + files , '.\\' + path + '\\src\\' + files)
    for files in glob('*.c'):
       shutil.move('.\\' + files , '.\\' + path + '\\src\\' + files)

NOTE: My use case had only one folder named tag_*, might be different for others, please modify wildcard accordingly.

I couldn't use shutil.move before as my first attempt was without adding the file name in the destination and it did not work very well so wanted to try moving with cmd line/ ps commands.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rookie_Coder2318