This project has moved. For the latest updates, please go here.

Post Custom Command - Not running script/batch file

Jan 11, 2015 at 11:59 PM
I am trying to run a .bat file which runs a python script after the filed have been moved to a network share, Below is what I added to the profile.

PostCustomCommandPath=C:\Sab\fix.bat
PostCustomCommandParameters=""""
PostCustomCommandHangPeriod=10
PostCustomCommandCritical=true
PostCustomCommandUISession=true
PostCustomCommandShowWindow=true

Here is the .bat file

@echo off
python c:\sab\directoryt.py

The .bat file works, I just can't get it to work when called from MCE. Here is part of the log.

2015-01-11T14:25:52 MCEBuddy.AppWrapper.Base --> Launching process c:\sab\fix.bat
2015-01-11T14:25:52 MCEBuddy.AppWrapper.Base --> Process arguments ""
2015-01-11T14:25:52 MCEBuddy.AppWrapper.Base --> UI Session Admin Process : True
2015-01-11T14:25:52 MCEBuddy.AppWrapper.Base --> Starting process as a UISession process with Admin privileges. This requires atleast 1 user to be logged into the system (remote desktop or locally)
2015-01-11T14:25:52 MCEBuddy.AppWrapper.Base --> Setting process priority to Normal
--> Process exited with code 0
2015-01-11T14:25:54 MCEBuddy.Engine.ConversionJob --> Finished end of conversion custom command, file size [KB] 1,833,259.00
INFORMATION> 2015-01-11T14:25:54 MCEBuddy.Engine.ConversionJob --> Success - All done!
INFORMATION> 2015-01-11T14:25:54 MCEBuddy.Engine.ConversionJob -->

Can anyone help? Thanks...
Coordinator
Jan 12, 2015 at 4:56 AM
Turn the echo on so one can see what the script is doing or if it's even being called
Jan 12, 2015 at 10:29 AM
I does not look like it is doing only thing. When I run the .bat file as a stand alone, the command windows opens up, prints a few statements, and then closes. When I try to run with MCE, nothing happens.
Jan 12, 2015 at 12:02 PM
Well I can now see that the process is being called, the command prompt box opens on the screen, and then closes. It still does not look like it is actually doing anything though. The 'Process arguments' line is blank because I don't want to pass any arguments. Is this ok?
Jan 13, 2015 at 10:54 PM
So to test the .bat process I put in a 'md' and it was able to create a directory. Is still does not seems to run the python script. Any suggestions on how I can get the python script to run. This is what I have now. It changes to the sab folder an then it runs the python script. Without the bat file, I can run fix.py from the sab folder and it works just fine.

cd "c:\sab"
c:\python27\python.exe "c:\sab\fix.py"
Jan 14, 2015 at 3:56 AM
Boomer, I suspect that the .PY extension is not registered as an Executable Extension = PATHEXT.
The other option is that the FTYPE value for PY is not set right.
You might in addition to fixing the Python association, change to Pythonw (Python for Windows) to eliminate the additional window.

Based on you behavior, I am almost certain that Python (.PY) files are not properly associated with the Python executable.

https://docs.python.org/2/using/windows.html
Python scripts (files with the extension .py) will be executed by python.exe by default. This executable opens a terminal, which stays open even if the program uses a GUI. If you do not want this to happen, use the extension .pyw which will cause the script to be executed by pythonw.exe by default (both executables are located in the top-level of your Python installation directory). This suppresses the terminal window on startup.

You can also make all .py scripts execute with pythonw.exe, setting this through the usual facilities, for example (might require administrative rights):
1.Launch a command prompt.
2.Associate the correct file group with .py scripts:
assoc .py=Python.File

3.Redirect all Python files to the new executable:
ftype Python.File=C:\Path\to\pythonw.exe "%1" %*
Jan 14, 2015 at 11:03 AM
tcanter97, thanks I have applied the updates that you have suggested but it still does not update when called from MCEBuddy. Here is what I have in my profile

PostCustomCommandPath=c:\sab\testfull.bat
PostCustomCommandParameters=""
PostCustomCommandHangPeriod=60
PostCustomCommandCritical=false
PostCustomCommandUISession=false
PostCustomCommandShowWindow=false


In the tesfull.bat file I have

pythonw c:\sab\fix.py

It runs ok as a stand alone. Any other suggestions?
Coordinator
Jan 14, 2015 at 1:36 PM
Try turning on your echo so you can see what the error message is. I would suggest instead of just calling pythonw, specify the full path to the executable in your batch file.

Jan 14, 2015 at 2:15 PM
Ok so here is the bat file

@echo
cd "c:\sab"
c:\python27\pythonw.exe c:\sab\fix.pyw

Here's the config file

PostCustomCommandPath=c:\sab\testfull.bat
PostCustomCommandParameters=""
PostCustomCommandHangPeriod=60
PostCustomCommandCritical=false
PostCustomCommandUISession=false
PostCustomCommandShowWindow=true

The python script will do a search for any folder on my Y drive that is equal to 'Season'. If any files are in the folder, if will update them as needed to add 'S01E01' to them so that they are visible in Plex.
Coordinator
Jan 14, 2015 at 4:00 PM
Did it work? If not what shows up in the log?

Jan 14, 2015 at 4:21 PM
Here is the log

2015-01-14T10:01:03 MCEBuddy.Transcode.CustomCommand --> Custom command parameters read ->
PostCustomCommandPath = c:\sab\testfull.bat
PostCustomCommandParameters =
PostCustomCommandHangPeriod = 60
PostCustomCommandCritical = False
PostCustomCommandUISession = False
PostCustomCommandShowWindow = True
PostCustomCommandExitCodeCheck = False
2015-01-14T10:01:03 MCEBuddy.Transcode.CustomCommand --> About to run custom command with parameters:
PostCustomCommandPath = c:\sab\testfull.bat
PostCustomCommandParameters =
PostCustomCommandHangPeriod = 60
PostCustomCommandCritical = False
PostCustomCommandUISession = False
PostCustomCommandShowWindow = True
PostCustomCommandExitCodeCheck = False
2015-01-14T10:01:03 MCEBuddy.AppWrapper.Base --> Launching process c:\sab\testfull.bat
2015-01-14T10:01:03 MCEBuddy.AppWrapper.Base --> Process arguments
2015-01-14T10:01:03 MCEBuddy.AppWrapper.Base --> UI Session Admin Process : False
2015-01-14T10:01:03 MCEBuddy.AppWrapper.Base --> Setting process priority to Normal
2015-01-14T10:01:03 MCEBuddy.AppWrapper.Base --> ECHO is on.
2015-01-14T10:01:03 MCEBuddy.AppWrapper.Base --> c:\sab>cd "c:\sab"
2015-01-14T10:01:03 MCEBuddy.AppWrapper.Base --> c:\sab>c:\python27\pythonw.exe c:\sab\fix.pyw
--> Process exited with code 0
2015-01-14T10:01:05 MCEBuddy.Engine.ConversionJob --> Finished end of conversion custom command, file size [KB] 1,371,663.00
INFORMATION> 2015-01-14T10:01:05 MCEBuddy.Engine.ConversionJob --> Success - All done!
INFORMATION> 2015-01-14T10:01:05 MCEBuddy.Engine.ConversionJob -->
--> Performance Metrics for the Current Conversion
Coordinator
Jan 14, 2015 at 5:22 PM
wierd, either it isn't running or the output isn't being directed to standard output.
Try something simple, in your batch file call some other program and see if it launches.

Also try setting
PostCustomCommandUISession = True

Jan 14, 2015 at 7:26 PM
I set PostCustomCommandPath = C:\comskip\ComskipINIEditor.exe

This opened the UI INI editor without issues
Jan 14, 2015 at 7:52 PM
Try this to capture stdout and errout
C:\python27\pythonw.exe c:\sab\fix.pyw 2>&1
That redirects the street stream to stdout, it might capture any errors

Sent from my Windows Phone

Jan 14, 2015 at 8:02 PM
So here is the updated bat file

@echo
cd "c:\sab"
c:\python27\pythonw.exe c:\sab\fix.pyw 2>&1


This works when manually executed. Where would logging be placed?

Here is the config

PostCustomCommandPath=c:\sab\testfull.bat
PostCustomCommandParameters=""
PostCustomCommandHangPeriod=60
PostCustomCommandCritical=false
PostCustomCommandUISession=true
PostCustomCommandShowWindow=true
Coordinator
Jan 14, 2015 at 8:05 PM
it should be captured by MCEBuddy in the conversion log. All output to console is captured in the log

Jan 14, 2015 at 8:11 PM
Oh, I assumed the command wrapper was capturing stdout.
C:\python27\pythonw.exe c:\sab\fix.pyw 2>&1 > %temp%\mcelog-%random%.log

Find the log in %temp% named mcelog-arandonnumber.log

Sent from my Windows Phone

Jan 14, 2015 at 8:12 PM
I do not see anything in the mcebuddy.log file or the log file for the specific conversion.
Jan 14, 2015 at 8:12 PM
That's what I assumed...

Feature request, can you capture stderr in a future build?

Sent from my Windows Phone

Coordinator
Jan 14, 2015 at 8:17 PM
Edited Jan 14, 2015 at 11:27 PM
actually we do redirect stderr to the console output
Jan 14, 2015 at 8:18 PM
Try this (debugging purposes only)

add the commands:
Echo my current dir is %cd%
Echo python check
Dir c:\python27\python*.*
Echo script check
Dir c:\sab\*.*
Echo Python access check
C:\python27\pythonw.exe -? 2>&1
Echo Executing the script
C:\python27\pythonw.exe c:\sab\fix.pyw 2>&1
Echo errorlevel from the python script is %errorlevel%
Echo done executing the script

Sent from my Windows Phone

Jan 14, 2015 at 8:30 PM
Here is the what I get when I run it manually

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>cd \

C:>cd sab

C:\Sab>testfull
ECHO is on.

C:\Sab>Echo my current dir is C:\Sab
my current dir is C:\Sab

C:\Sab>Echo python check
python check

C:\Sab>Dir c:\python27\python*.*
Volume in drive C is OS
Volume Serial Number is A0EE-E594

Directory of c:\python27

07/04/2010 07:44 AM 27,136 python.exe
07/04/2010 07:53 AM 27,648 pythonw.exe
           2 File(s)         54,784 bytes
           0 Dir(s)  800,923,570,176 bytes free
C:\Sab>Echo script check
script check

C:\Sab>Dir c:\sab*.*
Volume in drive C is OS
Volume Serial Number is A0EE-E594

Directory of c:\sab

01/14/2015 04:26 PM <DIR> .
01/14/2015 04:26 PM <DIR> ..
01/12/2015 09:37 AM 2,052 directory.py
01/12/2015 02:27 PM 39 fix.bat
01/14/2015 06:53 AM 1,786 fix.py
01/14/2015 09:46 AM 1,785 fix.pyw
01/10/2015 03:58 PM <DIR> MCEBuddyArchive
01/14/2015 01:30 PM 0 output.txt
01/14/2015 09:21 AM 207 python tablo55.py -tvdirX -delay300 -mp4tagFalse -mce -mp4False -tvcreateFalse -debug -a -sleep1800.txt
01/14/2015 04:26 PM 2,094 tablo.history
01/14/2015 04:26 PM 128,563 tablo.log
01/12/2015 06:43 AM 71,323 tablo.py
01/01/2015 06:49 PM 51,045 tablo55.py
01/13/2015 08:33 AM 51 test.bat
01/14/2015 04:27 PM 334 testfull.bat
01/13/2015 07:45 PM 24 testy.bat
01/14/2015 04:26 PM <DIR> tv
          13 File(s)        259,303 bytes
           4 Dir(s)  800,923,570,176 bytes free
C:\Sab>Echo Python access check
Python access check

C:\Sab>C:\python27\pythonw.exe -? 2>&1

C:\Sab>Echo Executing the script
Executing the script

C:\Sab>C:\python27\pythonw.exe c:\sab\fix.pyw 2>&1

C:\Sab>Echo errorlevel from the python script is 0
errorlevel from the python script is 0

C:\Sab>Echo done executing the script
done executing the script

C:\Sab>
Jan 14, 2015 at 9:09 PM
Here is what I see when it's run from MCEBuddy

2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Launching process c:\sab\testfull.bat
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Process arguments
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> UI Session Admin Process : True
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Starting process as a UISession process with Admin privileges. This requires atleast 1 user to be logged into the system (remote desktop or locally)
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Setting process priority to Normal
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> ECHO is on.
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>Echo my current dir is c:\sab
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> my current dir is c:\sab
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>Echo python check
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> python check
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>Dir c:\python27\python*.*
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Volume in drive C is OS
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Volume Serial Number is A0EE-E594
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Directory of c:\python27
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 07/04/2010 07:44 AM 27,136 python.exe
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 07/04/2010 07:53 AM 27,648 pythonw.exe
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 2 File(s) 54,784 bytes
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 0 Dir(s) 800,919,691,264 bytes free
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>Echo script check
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> script check
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>Dir c:\sab*.
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Volume in drive C is OS
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Volume Serial Number is A0EE-E594
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Directory of c:\sab
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/14/2015 04:26 PM <DIR> .
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/14/2015 04:26 PM <DIR> ..
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/12/2015 09:37 AM 2,052 directory.py
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/12/2015 02:27 PM 39 fix.bat
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/14/2015 06:53 AM 1,786 fix.py
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/14/2015 09:46 AM 1,785 fix.pyw
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/10/2015 03:58 PM <DIR> MCEBuddyArchive
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/14/2015 01:30 PM 0 output.txt
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/14/2015 09:21 AM 207 python tablo55.py -tvdirX -delay300 -mp4tagFalse -mce -mp4False -tvcreateFalse -debug -a -sleep1800.txt
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/14/2015 04:26 PM 2,094 tablo.history
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/14/2015 04:56 PM 129,024 tablo.log
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/12/2015 06:43 AM 71,323 tablo.py
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/01/2015 06:49 PM 51,045 tablo55.py
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/13/2015 08:33 AM 51 test.bat
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/14/2015 04:27 PM 334 testfull.bat
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/13/2015 07:45 PM 24 testy.bat
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 01/14/2015 04:40 PM <DIR> tv
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 13 File(s) 259,764 bytes
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> 4 Dir(s) 800,919,625,728 bytes free
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>Echo Python access check
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Python access check
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>C:\python27\pythonw.exe -? 2>&1
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> usage: C:\python27\pythonw.exe [option] ... [-c cmd | -m mod | file | -] [arg] ...
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Options and arguments (and corresponding environment variables):
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -c cmd : program passed in as string (terminates option list)
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -d : debug output from parser; also PYTHONDEBUG=x
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -E : ignore PYTHON
environment variables (such as PYTHONPATH)
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -h : print this help message and exit (also --help)
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -i : inspect interactively after running script; forces a prompt even
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> if stdin does not appear to be a terminal; also PYTHONINSPECT=x
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -m mod : run library module as a script (terminates option list)
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -OO : remove doc-strings in addition to the -O optimizations
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -s : don't add user site directory to sys.path; also PYTHONNOUSERSITE
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -S : don't imply 'import site' on initialization
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -t : issue warnings about inconsistent tab usage (-tt: issue errors)
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> see man page for details on internal buffering relating to '-u'
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -v : verbose (trace import statements); also PYTHONVERBOSE=x
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> can be supplied multiple times to increase verbosity
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -V : print the Python version number and exit (also --version)
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -W arg : warning control; arg is action:message:category:module:lineno
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> also PYTHONWARNINGS=arg
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -x : skip first line of source, allowing use of non-Unix forms of #!cmd
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> -3 : warn about Python 3.x incompatibilities that 2to3 cannot trivially fix
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> file : program read from script file
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> - : program read from stdin (default; interactive mode if a tty)
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> arg ...: arguments passed to program in sys.argv[1:]
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Other environment variables:
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> PYTHONSTARTUP: file executed on interactive startup (no default)
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> PYTHONPATH : ';'-separated list of directories prefixed to the
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> default module search path. The result is sys.path.
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> PYTHONHOME : alternate <prefix> directory (or <prefix>;<exec_prefix>).
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> The default module search path uses <prefix>\lib.
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> PYTHONCASEOK : ignore case in 'import' statements (Windows).
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>Echo Executing the script
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> Executing the script
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>C:\python27\pythonw.exe c:\sab\fix.pyw 2>&1
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>Echo errorlevel from the python script is 0
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> errorlevel from the python script is 0
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> c:\sab>Echo done executing the script
2015-01-14T17:06:27 MCEBuddy.AppWrapper.Base --> done executing the script
--> Process exited with code 0
2015-01-14T17:06:30 MCEBuddy.Engine.ConversionJob --> Finished end of conversion custom command, file size [KB] 1,333,855.00
INFORMATION> 2015-01-14T17:06:30 MCEBuddy.Engine.ConversionJob --> Success - All done!
INFORMATION> 2015-01-14T17:06:30 MCEBuddy.Engine.ConversionJob -->
--> Performance Metrics for the Current Conversion
-->
Jan 14, 2015 at 10:22 PM

I am very confused, it was my hope that something would come to the fore when doing all these checks and it is not.

What is in the python script you are running, maybe it is failing early.

Jan 14, 2015 at 11:01 PM
Edited Jan 14, 2015 at 11:05 PM
Ok not a coder, as you will be able to tell, but here it is..
# Import the os module, for the os.walk function
import os
import time 

i=1
# Set the directory you want to start from
rootDir = 'Y:/TV Shows'
for dirName, subdirList, fileList in os.walk(rootDir):
    #print('Found directory: %s' % dirName)
    for fname in fileList:
        i=i
        
    dir_root, folname = os.path.split(dirName)  #get the dir and base names
    #print folname
    if folname == 'Season':
        cpt = sum([len(files) for r, d, files in os.walk(dirName)])
        print dir_root +'/'+ folname+ ' - Files in folder ' + str(cpt)
        if cpt == 0:
            #print 'ZERO'
            new_del = os.path.join(dir_root, folname)
            #print new_del
            os.rmdir(new_del)
        for fname in fileList:
            if fname[-8:] =='SE -.mkv':
                #print 'DIRNME ' + dirName
                s = '-'
                place = fname.find(s)
                #print place-1
                newname = fname[:place-1]
                #print newname
                #new_base = newname +' - S01E0' +str.format('{i}',i=i) + '.mkv'
                new_base = newname +' - S01E0' +str(cpt) + '.mkv'
                #print 'new base ' + new_base
                new_name = os.path.join(dirName, new_base)
                old_name = os.path.join(dirName, fname)

                file_to_rename = os.path.join(dirName, fname)
        
                #print 'Renaming %s to %s' % (old_name,new_name)
                try:
                    #print 'Renaming'
                    os.rename(old_name, new_name)
                except WindowsError as e:
                    #print e                
                    time.sleep(1)
            else:
                ''
                #print 'No Issues with the file ' + fname
Coordinator
Jan 14, 2015 at 11:30 PM
Is Y drive a mapped drive? If you need to read the documentation on how to use mapped drives from MCEBuddy (runs in kernel space unless you're using the UI feature)
Jan 14, 2015 at 11:35 PM
Yes, it's a mapped drive. I will have a look, thanks
Jan 15, 2015 at 12:10 AM

You might be fighting more battles than necessary…

You want to take all files missing Episode Names and rename with default episode names?

Here is a batch script DOS that does the same (I hope… you may need to debug)

(replace the fancy “” with normal quotes, I’m on a flight and am out of time)

ECHO ON

:: NOTE The ! Character is used to delay expansion of variable in DOS,

:: i.e. it doesn’t evaluate until the command is executed

:: when the ENABLEDELAYEDEXPANSION is turned on

:: with this we can update variable on the fly... added in Windows 2000

SETLOCAL ENABLEDELAYEDEXPANSION

SET I=0

:: If the folder already has files, set the I value to the next file name value

for /f %%d in ('dir “Y:\TV Shows”^| findstr “File(s)”') do SET /A I = %%d + 1

for /f “delims=“ %%f in (‘dir “Y:\TV Shows”’) do (

:: Increment I for each loop

SET /A I = I + 1

:: extract the file name without path or extension, i.e. D:\Foo\Far.txt returns Far

Set MyFile=%%~nf

:: compare the last 4 characters of the file name to the bad name

IF /I “!MyFile:~-4!” EQU “SE -” (

SET NEWFILE=%%~nf

SET MAXLOOPS = 5000

:LOOPRename

:: Increment the I variable until I find a good file name

SET /A I = I + 1

:: If the file exist, and the Max value has not been reached, loop and try

:: a bigger value

:: use the Max value counter to give a limit to how far to search

IF EXISTS “!NEWFILE:~0,-4! - S01E0 - !I!.mkv” IF “!I!” LEQ “!MAXLOOPS!” GOTO :LOOPRename

IF “!I!” GEQ “!MAXLOOPS!” (

CALL :ERROR %%f

) ELSE (

:: Ok, we have a new file, set the file name

SET NEWFILE=!NEWFILE:~0,-8! - S01E0 - !I!.mkv

:: and rename it using the dos command

Ren “%%f” “!NEWFILE!”

)

) else (

Echo The file was valid, no need to rename

)

)

GOTO :EOF

:ERROR

ECHO The folder has more than 5000 files in it and cannot rename %1

:: GOTO :EOF returns from the called routine

GOTO :EOF

Jan 15, 2015 at 1:01 AM
Go figure, it works now when I map the network drive the proper way. Thanks all for the help.
Marked as answer by rboy1 on 1/14/2015 at 7:26 PM
Coordinator
Jan 15, 2015 at 1:57 AM
the devils's in the details :)
Map drives are one of the few finicky things in MCEBuddy since it's a Windows limitation and we can't work around it (user context vs kernel context). almost every "major" issue anyone has faced with custom commands is to do with mapped drives.

Coordinator
Jan 15, 2015 at 2:27 AM
Jan 15, 2015 at 2:28 AM

I run MCEBuddy under a custom account and connect the network shares via \\Servername\Share approach, still requires mapping, but you only have to logon to the account once.

I admit that the MCEBuddy process needs a lot of permissions, and I’m still mapping them out.

Coordinator
Jan 15, 2015 at 2:58 AM
you could just run mcebuddy as a command line service from the start menu (set to start from task scheduler), that way mcebuddy can you use all your locally mapped drives.