V
V
vadimeasy2021-10-28 17:15:00
Python
vadimeasy, 2021-10-28 17:15:00

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)

After starting I get an error:
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'

Help me understand what is the reason?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Viktor Golovanenko, 2021-10-28
@vadimeasy

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)

R
Ruslan Sadikhov, 2015-01-21
@fsdsdfsfdsfsdfsdfsdfsdfsd

Most likely, you need to download Windows Installer Cleanup - support.microsoft.com/kb/290301
answers.microsoft.com/en-us/windows/forum/windows_...

R
RiON69, 2015-01-22
@RiON69

Try running the Python installer, choose to fix or install. Then try uninstalling through add/remove programs in control panel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question