Script fails with Failed to make directory

Post Reply
cwswitch
Member
Posts: 78
Joined: Fri Feb 24, 2017 12:25 am

Script fails with Failed to make directory

Post by cwswitch »

Hi, we're not sure where this error lies, but seems to be a write permission. We have tried running with our network administrators account and with our switch account (which is already an administrator)

In all cases we receive the error

Code: Select all

29/11/2017 8:45:24 AM,Error,SwitchScript1,test write,Script element,,,Error in line 16 of script : Error. Failed to make directory 'testtest'

Code: Select all

// Is invoked each time a new job arrives in one of the input folders for the flow element.
// The newly arrived job is passed as the second parameter.
function jobArrived( s : Switch, job : Job )
{
	s.log(3,"jobArrived test write triggered");
	var dir = new Dir("C:\JOBS\J000029\Client\PDF");
	dir.mkdir("testtest");
}

// Is invoked at regular intervals regardless of whether a new job arrived or not.
// The interval can be modified with s.setTimerInterval().
function timerFired( s : Switch )
{
	s.log(3,"timerFired test write triggered");
	var dir = new Dir("C:\JOBS\J000029\Client\PDF");
	dir.mkdir("testtest");
}
The script is attempting to write to the local disk as we thought the error was when we were trying to write to the job server, but the error still occurs when writing to our local C drive.
Paul Lewis
Newbie
Posts: 2
Joined: Mon Mar 20, 2017 7:30 am

Re: Script fails with Failed to make directory

Post by Paul Lewis »

You need to escape / add double backslashes in your base folder object (which is "dir").

EG
s.log(3,"jobArrived test write triggered");
var dir = new Dir("C:\\JOBS\\J000029\\Client\\PDF");
dir.mkdir("testtest");
cwswitch
Member
Posts: 78
Joined: Fri Feb 24, 2017 12:25 am

Re: Script fails with Failed to make directory

Post by cwswitch »

WooHooo

Thanks!

Incase anyone needs to know, you escape all backslashes, so

Code: Select all

\\foo\bar 
becomes

Code: Select all

\\\\foo\\bar
bens
Advanced member
Posts: 252
Joined: Thu Mar 03, 2011 10:13 am

Re: Script fails with Failed to make directory

Post by bens »

A little known fact is that in many places Windows can handle forward slashes in paths. Instead of using "C:\\JOBS\\J000029\\Client\\PDF", try "C:/JOBS/J000029/Client/PDF".

This may not work everywhere, but often it does.
Post Reply