Answer the question
In order to leave comments, you need to log in
How to move a file with a specific extension from one folder to another?
Good afternoon, I'm making an automation program and I need to move files from one folder to another with a specific extension.
Here is the code:
source_path = (r'C:/Users/kolom/Desktop/Main programm/Auto_EGAIS/exe/.*ovpn')
destination_path = (r'C:/Program Files/OpenVPN/config')
shutil.copy2 (source_path, destination_path)
Traceback (most recent call last):
File "c:\Users\kolom\Desktop\Main programm\Auto_EGAIS\exe\main.py", line 13, in <module>
shutil.copy2 (source_path, destination_path)
File "C:\Users\kolom\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 443, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\kolom\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 265, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
OSError: [Errno 22] Invalid argument: 'C:/Users/kolom/Desktop/Main programm/Auto_EGAIS/exe/.*ovpn'
Answer the question
In order to leave comments, you need to log in
Use the glob module from the standard library to find files that match a pattern. The files_to_copy variable will contain all files in the folder (with full path) that end in ".ovpn":
import glob
import shutil
files_to_copy = glob.glob('C:/Users/kolom/Desktop/Main programm/Auto_EGAIS/exe/*.ovpn')
destination_path = (r'C:/Program Files/OpenVPN/config/')
for file in files_to_copy:
shutil.copy2(file, destination_path)
Most likely, you need to download Windows Installer Cleanup - support.microsoft.com/kb/290301
answers.microsoft.com/en-us/windows/forum/windows_...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question