i'm trying to create a script with python that creates sample folder if a sample file exists and the move the file to folder (also for proof and subs). i'm using python, but i'm fairly new to programming. there seem to be a function to automatically delete these files, but not to create the folders like the original release? :\
anyway, here is my code:
Code: Select all
import os
import sys
import shutil
workDir = os.environ['SAB_COMPLETE_DIR']
print(workDir)
for root, dirs, files in os.walk(workDir):
for f_name in files:
if f_name.endswith('.mkv'):
sampleDir = workDir + '/Sample/'
os.mkdir(sampleDir)
shutil.move(f_name, sampleDir)
sys.exit(0)
Code: Select all
/data/Joe.Pera.Talks.With.You.S01E01.720p.HDTV.x264-MiNDTHEGAP
Traceback (most recent call last):
File "/usr/lib/python3.8/shutil.py", line 788, in move
os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: 'joe.pera.talks.with.you.s01e01.720p.hdtv.x264.sample-mtg.mkv' -> '/data/Joe.Pera.Talks.With.You.S01E01.720p.HDTV.x264-MiNDTHEGAP/Sample/joe.pera.talks.with.you.s01e01.720p.hdtv.x264.sample-mtg.mkv'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/admin/clean_supportfiles.py", line 12, in <module>
shutil.move(f_name, sampleDir)
File "/usr/lib/python3.8/shutil.py", line 802, in move
copy_function(src, real_dst)
File "/usr/lib/python3.8/shutil.py", line 432, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/lib/python3.8/shutil.py", line 261, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: 'joe.pera.talks.with.you.s01e01.720p.hdtv.x264.sample-mtg.mkv'
any help would be much appreciated