Jump to content
Developer Wiki and Function Reference Links ×

Bad file name Question


Recommended Posts

Anyone know why this code:

 

Procedure T;

VAR

s1 : STRING;

BEGIN

s1 := Concat(GetFolderPath(1), 'Test.txt');

ReWrite(s1);

WriteLn('test');

Close(s1);

END;

Run(T);

 

works fine on a Mac but returns this error on a PC:

 

Error on line=6: T S1 - File operation returned error.

Error on line=8: T S1 - Bad file name. C:\Program Files\Vectorworks 2018\Test.txt

 

Thanks!

Link to comment

From the Function Reference Notes on GetFolderPath:

 

Note that use of the negative values of these constants can be used to get the user-based folder path. The positive values are for application-based paths, which should not be used for writing.

 

So try and see if you can get what you want with GetFolderPath(-1).

 

 

Link to comment

I think you need to specify a separater character. GetFolderPath() does not end in a ":" or a "\".   You might try:

 

        IF Platform = 1 THEN
            sepChar := ':'
        ELSE
            sepChar := '/';

        s1 := Concat(GetFolderPath(-1), sepChar,  'Test.txt');

 

I would share some code from my scripts, but they just collect file names;

For example

 

        IF Platform = 1 THEN
            sepChar := ':'
        ELSE
            sepChar := '/';
            

        cableCt := 0;

        index := 1;
        folderPath := CONCAT(GetFolderPath(-2), kMasterInventoryFolder, sepChar, kMultFileFolder);
        fileName := GetFilesInFolder(folderPath, index);

        WHILE (GetFilesInFolder(folderPath, index) <> '') DO
            BEGIN
                fileName := GetFilesInFolder(folderPath, index);
                suffix := COPY(fileName, LEN(fileName)-3, 4);
                IF COPY(fileName, LEN(fileName)-3, 4) = '.xml' THEN
                    BEGIN
                        cableCt := cableCt + 1;
                        MultXMLList[cableCt] := fileName;
                    END;
                index := index + 1;
            END; {WHILE (MultXMLList[index] <> '')}
 

Link to comment

Thanks guys.

Nicolas: I am the admin user on both machines and if it works on a Mac then, should it not work on a PC? Still, maybe you are right.

Pat:  Message(GetFolderPath(-1));  also returns the path to application folder on Mac and PC.

Sam: If you run  Message(GetFolderPath(1));  you will see it does return a separator at the end of the path name.

Link to comment
On 8/4/2018 at 6:48 AM, Julian Carr said:

Thanks guys.

Nicolas: I am the admin user on both machines and if it works on a Mac then, should it not work on a PC? Still, maybe you are right.

 I did a quick test in my Mac. I can create a file (from the command line, not from VW) in /Applications. However I cannot do the sampe in C:\Program Files on Windows. That is how both operating systems work.

 

(Being an admin user on Windows, does not mean that unpriviledged programs like VW have admin rights to write files.)

Edited by Nicolas Goutte
Link to comment
  • 3 weeks later...
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...