[UNRAID DOCKER] Script to create folder and move files

Come up with a useful post-processing script? Share it here!
Post Reply
Ralph_Wiggum
Newbie
Newbie
Posts: 11
Joined: September 11th, 2012, 12:02 pm

[UNRAID DOCKER] Script to create folder and move files

Post by Ralph_Wiggum »

hi!

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)
and here is the result:

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'
so the scripts creates the folder and seem like it tries to move, but then it doesn't. is my code off, or could this be a permissions thing? i'm not sure how it works since i think the incoming folder on the array is mounted in the docker container.

any help would be much appreciated
User avatar
sander
Release Testers
Release Testers
Posts: 9070
Joined: January 22nd, 2008, 2:22 pm

Re: [UNRAID DOCKER] Script to create folder and move files

Post by sander »

f_name is just a filename .... but in which directory ... ???

So make sure shutil.move() uses a full path for the file name
Ralph_Wiggum
Newbie
Newbie
Posts: 11
Joined: September 11th, 2012, 12:02 pm

Re: [UNRAID DOCKER] Script to create folder and move files

Post by Ralph_Wiggum »

well now i feel stupid :-[

the info i found said
To move a file or directory to another location, use shutil.move(src, dst). src is the file or directory to be moved and dst is the destination:
so i just assumed filename was enough :\

thanks a lot though, that worked like a charm :D
Post Reply