Jump to content
Julian Carr

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!

Share this post


Link to post

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).

 

 

Share this post


Link to post

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] <> '')}
 

Share this post


Link to post

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.

Share this post


Link to post
Posted (edited)
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

Share this post


Link to post

OK thanks for the confirmation Nicolas. Interesting that Vw can write to the Libraries folder though. I guess that's a slightly different mechanism though.

Share this post


Link to post

I am not sure but I suppose that the installer makes the Library folder writable due to the library cache files.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×