Jump to content

Can Spotfire create new folder in a local shared drive provided it has access using ironpython


Roshan Kumar Patra
Go to solution Solved by Fredrik Rosell,

Recommended Posts

Hello Everyone,

I am exporting set of tables to a shared drive using ironpython. User can click on a button and it will export the set of tables as flat files to a defined shared drive.

Now the new requirement is to create a new folder and save the files in that folder with export timestamp. Do not want to overwrite the existing files

I have attached the script that i am already using.

Can anyone help me on this? thanks in advance

from System.IO import Filefrom Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiersfrom Spotfire.Dxp.Application.Filters import RangeFilter, ValueRangefrom Spotfire.Dxp.Data.DataType import Datefrom System import DateTimefset = 0 for data in Document.Data.Tables: try: filt=Document.FilteringSchemes[0].Item[data].Item[data.Columns.Item["DT_TS"]].As[RangeFilter]() fset = 1 except: fset = 0 if fset == 1: writer = Document.Data.CreateDataWriter(DataWriterTypeIdentifiers.ExcelXlsxDataWriter) table = data filtered = Document.ActiveFilteringSelectionReference.GetSelection(table).AsIndexSet() stream = File.OpenWrite(r"\ABCd_" + data.Name + ".xlsx") names =[] for col in table.Columns: names.append(col.Name) writer.Write(stream, table, filtered, names) stream.Close()
Link to comment
Share on other sites

  • Solution

Hello,

That is not done using Spotfire-specific functionality so I would recommend exploring general (Iron)Python documentation on that topic.

I did a very quick test. My first google hit for this was https://www.freecodecamp.org/news/creating-a-directory-in-python-how-to-create-a-folder/ and following that, using os.mkdir(path) to create the folder and os.path.exists(path) to check for existing folders worked fine (tested using a shared drive, using a UNC path). But again, I recommend looking at Python documentation for pros and cons etc on various approaches for this.

Link to comment
Share on other sites

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
×
×
  • Create New...