Jump to content

Delete a text file (.txt)

Recommended Posts

I was wondering if there is a way to delete a text file (.txt) using a script.  I have various hole pattern files saved per a height code and a number saved to multiple text files (93AA-1.txt) which are being read to populate a dialog list browser and using the Read procedure. 93AA-1.txt has 20 parameters to populate line 1 of the list, 93AA-2.txt populates line 2 and so on for a limit of 9.  If the user wants to delete one of the patterns, I was hoping to delete the file to show the correct pattern list.  I tried to do all of the patterns in a single text file (ReadLn) but was unsuccessful in getting the pointer to read the correct line.


Any thoughts or help would be appreciated.


Link to comment
  PythonExecute( 'import os' );
  PythonExecute( 'os.remove( r"C:\Users\admin\Desktop\remove.txt")' );

This should do it. Make sure the file is in a dir where VW has the permission to delete it.




  • Like 1
Link to comment

Thanks Pat, that works great.  One question, is there a way to make the file path contain variables?  I get an error when I try.

here is my method for finding the filepath to insure it exist before populating the dialog:


    fileName:=Concat('C:\Users\Eric\AppData\Roaming\Nemetschek\Vectorworks\2014\Stud Patterns\',FileCode,Ext,'.txt');

    GetFileInfo(fileName, fullReadPath, fullWritePath, readFileExists, writeFileExists, locked, hasReadPermission, hasWritePermission, hasFolderPermission);

Link to comment

Check out the VS.GetVSVar function https://developer.vectorworks.net/index.php/VS:GetVSVar


This will bring a Vectorscript Variable into Python Variable.


I filed a bug in November. If you pass a String variable through this function it loses the first character. If you pass a DynArray of Char it works properly. It is supposed to be fixed in SP3 whenever that is released.


Apparently the bug also impact the reverse function VS.SetVSVar.

  • Like 1
Link to comment

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.

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