"unable To Write File" Error When Executing Script, Unable to write new file in non-protected directory |
"unable To Write File" Error When Executing Script, Unable to write new file in non-protected directory |
Jun 30 2006, 03:20 AM
Post
#1
|
|
Forum Member Group: Members Posts: 19 Joined: 8-September 01 Member No.: 79 |
OS/2 4.52 Japanese
PMView Pro 3.24 I've a crude REXX script that helps me write PPWizard headers for home page generation. When I drop a JPEG file on it, it calls PMView to do the file resizing and save. It is supposed to: copy a file to the tmp directory, Create a PMView script there opes the file with PMView and save it resized in another directory. There is about 148 MB worth of free space on the disk, but now and then I get the following error message: Unable to write file F:\sagyo\workshop\source\..\text\images\report\mb5h0087.jpg (Check that the file or disk is not write protected and that there is free space on the disk) I suspect PMView involvement because the right panel of the "Confirm file replace" which appears if I copy a file to the target directory shows a black image.. However, although it has worked reliably until today, it is also possible I've somehow messed something up in the script. I include it below in case someone should have the time & inclination to check whether I'm missing something glaringly obvious... Thanks /* REXX script to generate photo captions for PPWizard to include in reports. */ /* Assumes the first four letters of each filename to be the file creation */ /* basedate in base 32 notation. */ Options 'EXMODE' Call rxfuncadd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' Call Sysloadfuncs scratchfile = "scratchfile.txt" tempscript = "tempscript.scr" tempdir = value( "TMP",, "os2environment" ) Parse Arg filename filename=Lower(filename) lp=lastpos("\",filename) Parse Var filename . +(lp) shortname Parse Var shortname datestring +4 . /* convert 32 bit date to basedate */ bdate=Ttb2d(datestring) /* convert basedate date to yyyymmdd */ jdate=Basedate2julian(bdate) /* Switch focus to this script */ Parse Source . . scriptname lp=lastpos("\",scriptname)-1 Parse Var scriptname sourcedir +(lp) . +1 scriptname rc=Sysswitchsession(scriptname) /* get file description & subtitle */ Say "Write file description & subtitle in Japanese" scratchfile = Get_tempfile(scratchfile) rc=lineout(scratchfile,"description") rc=lineout(scratchfile,"subtitle") rc=stream(scratchfile,"C","Close") "call e.exe" scratchfile txt=charin(scratchfile,1,chars(scratchfile)) rc=stream(scratchfile,"C","Close") rc=Sysfiledelete(scratchfile) delim="0d0a"x Parse Var txt description (delim) subtitle (delim) . subtitle=strip(subtitle) If left(translate(subtitle),8)="SUBTITLE" Then Do Parse Var subtitle . "subtitle" subtitle subtitle=strip(subtitle) End addtext="<$photo0x>" || shortname ||"<$photo1x>"|| description || "<$photo2x>" || subtitle ||"<$photo3x>" || "0d0a"x Say "Add '"||description||":"||subtitle "to r-" || jdate ||"-p.ih?" If Yesno()=0 Then Exit Else Do rc=lineout(sourcedir||"\r-"||jdate||"-p.ih",addtext) End /* Make temporary pmview script */ tempscript=Get_tempfile(tempscript) rc=lineout(tempscript,"PMView Script") rc=lineout(tempscript,"Resize;letterbox=no;proportional=yes;resample=yes;width=340") rc=lineout(tempscript,"OutputDir;dirname=" || sourcedir || "\..\text\images\report;useoriginaldir=no") rc=lineout(tempscript,"Resolution;horizontal=23622;unit=metric;vertical=23622") rc=lineout(tempscript,"FileFormat;filetype=JFIF") rc=stream(tempscript,"C","Close") /* This section needs work - all files should have .jpg extension */ rc=Sysfiledelete(tempdir || "\" || shortname) cnt=charin(filename,1,chars(filename)) rc=charout(tempdir || "\" || shortname,cnt) rc= stream(tempdir || "\" || shortname,"C","Close") "e:\programs\pmview\pmview.exe /SingleInstance=PMViewX /Script="||tempscript tempdir||"\"||shortname rc=stream(filename,"C","Close") rc=stream(tempscript,"C","Close") rc=Sysfiledelete(tempscript) rc=Sysfiledelete(tempdir||"\"||shortname) rc=Sysswitchsession("File Open") Exit YESNO: Procedure Pull yesno Select When yesno="Y" Then Return 1 When yesno="HAI" Then Return 1 Otherwise Return 0 End Exit /* Convert 32 bit number to decimal */ TTB2D: Procedure Numeric Digits 10 Parse Upper Arg b32 s32="123456789ABCDEFGHIJKLMNOPQRSTUV" chuck=reverse(b32) d.0=length(b32) Do i=1 To d.0 x=i-1 Parse Var chuck . +(x) d.i +1 . End result=0 Do i=1 To d.0 n=pos(d.i,s32) n=n*((32**(i-1))) result=result+n End Return result Exit /* Convert basedate to julian date in yyyymmdd format */ BASEDATE2JULIAN: Procedure Parse Arg day Do year=1 While day>=365 day=day-365 Select When year//100=0 & year//400<>0 Then Nop When year//4=0 Then day=day-1 Otherwise Nop End End If year>1 Then day=day+1 /*There is no day 0. Special to handle year 1. */ md=1 Do month=1 Until day<md /*Do until total days < days in current month */ Select When month=2 Then Select When year//100=0 & year//400<>0 Then xd=28 When year//4=0 Then xd=29 Otherwise xd=28 End When month=4 | month=6 | month=9 | month=11 Then xd=30 Otherwise xd=31 End day=day-xd End If day<=0 Then day=day+xd /*If current days <=0 then add days in current month */ year=right(year,4,"0") month=right(month,2,"0") day=right(day,2,"0") Return year || month || day Exit UPPER: Procedure Parse Arg temp Return translate(temp,"ABCDEFGHIJKLMNOPQRSTUVWXYZ児壯","abcdefghijklmnopqrstuvwxyz・≪") LOWER: Procedure Parse Arg temp Return translate(temp,"abcdefghijklmnopqrstuvwxyz・≪","ABCDEFGHIJKLMNOPQRSTUVWXYZ児壯") /******************************************************************************** ******************* function: Check if a file, directory or device exists call: rc = FileExists( fileToTest ) where: fileToTest - name of the file to test returns: -2 - invalid parameter -1 - cannot detect (e.g. the drive is not ready) 0 - no file, device or directory with this name exists 1 - the file exists 2 - a device with this name exists 3 - a directory with this name exists ******************************************************************************** *******************/ FILEEXISTS: Procedure /* v2.90 - from RxTT35 */ Parse Arg filename /* install temporary error handler */ Signal On Notready Name Fileexistserror Signal On Failure Name Fileexistserror Signal On Error Name Fileexistserror Thisrc = -2 /* rc = -2 ->> invalid parameter */ /* check the parameter */ If strip( filename ) <> "" Then Do thisrc = -1 /* rc = -1 ->> cannot detect */ /* check whether the drive with the file is ready */ Call stream filename /* Lower error detection level to determine whether the name is that of a device (e.g. "LPT1") */ Signal Off Notready If stream( filename, "c", "QUERY EXISTS" ) <> "" Then Do /* seems that the file exists -- check wheter it is a device */ If stream( filename, "c", "QUERY DATETIME" ) == "" Then thisrc = 2 /* rc = 2 ->> a device name */ Else thisrc = 1 /* rc = 1 ->> a file name */ End Else Do /* The file apparently does not exist -- check whether a directory with the name exists */ /* Save the current directory of the current drive */ thisdir = directory() /* Save the current directory of the drive on which the target should exist */ tempdir = directory( filespec( "Drive", filename ) ) If directory( filename ) <> "" Then thisrc = 3 /* rc = 3 ->> a dir with this name exists */ Else thisrc = 0 /* rc = 0 ->> no file, device or directory with this name exists */ /* restore the current directory of the target drive */ Call directory tempdir /* restore the current directory of the current drive */ Call directory thisdir End End FILEEXISTSERROR: Return thisrc /******************************************************************************** ******************* FUNCTION: Designates temporary file name in "TMP" directory 2006.06.25 call: get_tempfile() returns: temp??.???, or if a template containing up to five ??:s has been given, whatever matches the template (e.g. tmp?????.scr) Requires: Rexxutil.dll fileexists countstr parsefn Notes: returned tempfile ALWAYS resides in "TMP" directory ******************************************************************************** *******************/ GET_TEMPFILE: Procedure Trace Off /*DEBUG */ tempdir = value( "TMP",, "os2environment" ) Parse Arg filename filename=strip(filename) /* Get rid of any path information. */ If pos(":",filename)=2 | Countstr("\",filename)>0 Then Do Parse Value Parsefn(filename) With . . chuck.name chuck.extension filename=chuck.name || "." || chuck.extension Drop chuck. End /* Note file extension */ chuck.extension=lastpos(".",filename) If lastpos(".",filename)>0 Then Parse Var filename filenamebody =(chuck.extension) fileext Drop chuck. Select When pos("?",filename) = 0 & Fileexists( tempdir || "\" || filename ) = 0 Then Return tempdir || "\" || filename When pos("?",filename) = 0 & fileext = "" Then filename = "tmp?????.tmp" When pos("?",filename) = 0 Then filename = "tmp?????" || fileext Otherwise Nop End Return Systempfilename(tempdir||"\"||filename ) /******************************************************************************** ******************* FUNCTION: Count Needles in a Haystack call: countstr needles,haystack where: needles = what to find and haystack = where to find them returns: number of needles in haystack Requires: nothing ******************************************************************************** *******************/ COUNTSTR: Procedure Trace Off /*DEBUG */ Parse Arg needle, haystack result=0 temp=pos(needle,haystack) Do While temp > 0 result=result+1 temp=pos(needle,haystack,temp+length(needle)) End Return result /******************************************************************************** ******************* FUNCTION: parses file name to driveletter, path, name and extension call: call ParseFN("e:\os2\cmd.exe") returns: e,\os2\,cmd,exe Requires: countstr ******************************************************************************** *******************/ PARSEFN: Procedure Trace Off /*DEBUG */ Parse Arg filename filename=strip(filename) p.="" If lastpos(":",filename)>0 Then Parse Var filename p.d ":" filename If length(p.d)>1 Then Return "" If Countstr("\",filename)>0 Then Do delim=lastpos("\",filename) Parse Var filename p.p +(delim) filename End If 0<Countstr(".",filename) Then Do delim=lastpos(".",filename)-1 Parse Var filename p.f +(delim) . +1 p.e End Else p.f=filename Return p.d||","||p.p||","||p.f||","||p.e
Attached File(s)
|
|
|
Jun 30 2006, 10:05 AM
Post
#2
|
|
Forum Member Group: Members Posts: 19 Joined: 8-September 01 Member No.: 79 |
OK. Calling syssleep 1 before pmview may be the solution. I'll need to play around a bit more to be sure, though.
|
|
|
Lo-Fi Version | Time is now: 11th November 2024 - 01:45 AM |