将文件从屏幕截图移动到其他文件夹



这是代码,它通过屏幕截图进行搜索,并获取具有特定字符串的屏幕截图。

import os
import shutil
#from pathlib import Path

#'E:\Test'
#if src = 'path/to/file.txt'
#grabs = 'C:\Users\Gal\Videos\Captures'
#'C:\Users\Gal\Videos\Captures'

directory = ('C:\Users\Gal\Videos\Captures')
target = ('C:\zorko')
destination = 'zorko'

for filename in os.listdir(directory):
data = str(filename)
final = 'teorija' in data
path = os.path.abspath(filename)
if final is True:
print('1')
shutil.move(filename, target)

然而,当试图用shutil移动它们时,它会显示以下错误:

Traceback (most recent call last):
File "C:UsersGalAppDataLocalProgramsPythonPython38-32libshutil.py", line 788, in move
os.rename(src, real_dst)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'T1A INF teorija _ Microsoft Teams 10_21_2020 10_39_27 AM.png' -> 'C:\zorko\T1A INF teorija _ Microsoft Teams 10_21_2020 10_39_27 AM.png'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Gal/PycharmProjects/pythonProject2/main.py", line 23, in <module>
shutil.move(filename, target)
File "C:UsersGalAppDataLocalProgramsPythonPython38-32libshutil.py", line 802, in move
copy_function(src, real_dst)
File "C:UsersGalAppDataLocalProgramsPythonPython38-32libshutil.py", line 432, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:UsersGalAppDataLocalProgramsPythonPython38-32libshutil.py", line 261, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: 'T1A INF teorija _ Microsoft Teams 10_21_2020 10_39_27 AM.png'
import os
import shutil
directory = ('C:\Users\Gal\Videos\Captures')
target = ('C:\zorko')
destination = 'zorko'
for filename in os.listdir(directory):
if 'teorija' in filename:
shutil.move(os.path.join(directory, filename), os.path.join(target, filename))

最新更新