[WINDOWS] Commas in Path and File

Come up with a useful post-processing script? Share it here!
Post Reply
ALbino
Full Member
Full Member
Posts: 214
Joined: October 23rd, 2014, 12:28 am

[WINDOWS] Commas in Path and File

Post 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!
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: [WINDOWS] Commas in Path and File

Post 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""
ALbino
Full Member
Full Member
Posts: 214
Joined: October 23rd, 2014, 12:28 am

Re: [WINDOWS] Commas in Path and File

Post 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.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: [WINDOWS] Commas in Path and File

Post 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.
ALbino
Full Member
Full Member
Posts: 214
Joined: October 23rd, 2014, 12:28 am

Re: [WINDOWS] Commas in Path and File

Post 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? :)
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: [WINDOWS] Commas in Path and File

Post 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.
ALbino
Full Member
Full Member
Posts: 214
Joined: October 23rd, 2014, 12:28 am

Re: [WINDOWS] Commas in Path and File

Post 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?
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: [WINDOWS] Commas in Path and File

Post by shypike »

It will be 0.7.19
ALbino
Full Member
Full Member
Posts: 214
Joined: October 23rd, 2014, 12:28 am

Re: [WINDOWS] Commas in Path and File

Post by ALbino »

Thanks so much for the help, and for what you and the other guys do for this project. Appreciate it.
Post Reply