Python Windows File Copy with Wildcard Support
- by Wang Dingwei
I've been doing this all the time:
result = subprocess.call(['copy', '123*.xml', 'out_folder\\.', '/y'])
if result == 0:
do_something()
else:
do_something_else()
Until today I started to look into pywin32 modules, then I saw functions like win32file.CopyFiles(), but then I found it may not support copying files to a directory. Maybe this functionality is hidden somewhere, but I haven't found it yet.
I've also tried "glob" and "shutil" combination, but "glob" is incredibly slow if there are many files.
So, how do you emulate this Windows command with Python?
copy 123*.xml out_folder\. /y