Page 1 of 1

[WINDOWS] Commas in Path and File

Posted: October 24th, 2014, 7:05 pm
by ALbino
Hey all,

I've very new to this, so this might be obvious. I have a few post-processing scripts I have written, mostly just to rename obfuscated files and move them to a different folder, but just today I ran into a problem where the NZB/Folder/File had a comma in it, and it switched my working directory to to my SABnzbd Program File folder and tried to execute there. An example might be:

TV.Show.S01E01.This,.That,.And.Another.Thing

I've been setting my working folder using:

Code: Select all

cd /d %1
But quickly realized it should probably be:

Code: Select all

cd /d "%1"
I thought I solved it, but when I tried to download the NZB again it still tried to execute in the SABnzbd folder with the error "The system cannot find the path specified.".

I had a similar problem before with spaces, but the program has an option to switch all spaces to underscores, and once I checked that there were no more issues. If I'm missing something, or if anybody has any advice on how to deal with the commas (or any other characters for that matter), I'd appreciate the help. Thanks!

Re: [WINDOWS] Commas in Path and File

Posted: October 25th, 2014, 5:10 am
by shypike
ALbino wrote: I thought I solved it, but when I tried to download the NZB again it still tried to execute in the SABnzbd folder with the error "The system cannot find the path specified.".
BTW: you don't need the extra quotes because SABnzbd already adds quotes to each parameter.
Normally you would need to add the quotes yourself, but due to an issue in one of the
software libraries we are using, the parameters always come with quotes.
This is only a problem when you try to concatenate paths (which you're not doing).

Anyway, remove the quotes because Windows doesn't handle double quotes very well.
This one works:
cd /d "test,me"
The next two are both wrong:
cd /d test,me
cd '/d ""test,me""

Re: [WINDOWS] Commas in Path and File

Posted: October 25th, 2014, 12:54 pm
by ALbino
I just wrote a very basic test script and it failed. Here's the code I just tried:

Code: Select all

echo off

echo.
echo Percent 1: %1
echo.
echo Percent 1 with quotes: "%1"
echo.
echo Current Directory: %CD%
echo.
echo Changing directories...
echo.

cd /d %1

echo.
echo New Directory: %CD%
echo.
Replacing the actual NZB name with "TV.Show.S01E01.This,.That,.And.Another.Thing" here is the output from SABnzbd:

Code: Select all

C:\Program Files (x86)\SABnzbd>echo off 

Percent 1: c:\temp\TV.Show.S01E01.This

Percent 1 with quotes: "c:\temp\TV.Show.S01E01.This"

Current Directory: C:\Program Files (x86)\SABnzbd

Changing directories...

The system cannot find the path specified.

New Directory: C:\Program Files (x86)\SABnzbd

So it failed on the comma, %1 didn't have any quotes, and "%1" with quotes still failed at the comma.

It unpacks fine, so internally it's working, it's only the script that gets messed up.

My worst case scenario was I would just check to see if there was a comma in the NZB/path and just exit with an error, but with %1 not showing the comma that won't work either.

Re: [WINDOWS] Commas in Path and File

Posted: October 25th, 2014, 2:19 pm
by shypike
It's a bug in the Python libraries.
A parameter with an embedded space is quoted.
One with an embedded comma is not, while it should.

I'm not sure whether I can fix this or not.
As you can see, the part after the comma is shifted to the next parameter.

Re: [WINDOWS] Commas in Path and File

Posted: October 25th, 2014, 2:46 pm
by ALbino
The best thing seems to be just to error and exit the script. I tried checking to see if %3 was in %1 but that fails too since %3 is also truncated because of the comma.

This is the last thing I tried with both %1 and "%1":

Code: Select all

echo off

echo.
echo Current Directory: %CD%
echo.

if exist %1 (
	echo The Folder exists, safe to proceed.
	cd /d %1
	echo.
	echo New Directory: %CD%
	echo.
	) else (
		echo.
		echo The Folder does not exist, error!
		echo.
)

echo.
echo Current Directory: %CD%
echo.
It failed as well, saying this:

Code: Select all

C:\Program Files (x86)\SABnzbd>echo off 

Current Directory: C:\Program Files (x86)\SABnzbd

\SABnzbd was unexpected at this time.
Do you have any other ideas? :)

Re: [WINDOWS] Commas in Path and File

Posted: October 25th, 2014, 2:47 pm
by shypike
Never mind.
I can fix it: there's already a work-around in SABnzbd, but it wasn't triggered by a comma yet.

Re: [WINDOWS] Commas in Path and File

Posted: October 25th, 2014, 2:55 pm
by ALbino
Great! Will that be in the next release? Is the next release an increment of 0.7.* or will it wait for 0.8?

Re: [WINDOWS] Commas in Path and File

Posted: October 25th, 2014, 2:58 pm
by shypike
It will be 0.7.19

Re: [WINDOWS] Commas in Path and File

Posted: October 25th, 2014, 3:01 pm
by ALbino
Thanks so much for the help, and for what you and the other guys do for this project. Appreciate it.