Roshan Kumar Patra Posted May 31, 2023 Share Posted May 31, 2023 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 filesI have attached the script that i am already using.Can anyone help me on this? thanks in advancefrom 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 More sharing options...
Solution Fredrik Rosell Posted June 5, 2023 Solution Share Posted June 5, 2023 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 More sharing options...
David Beagan 2 Posted June 5, 2023 Share Posted June 5, 2023 This is not a WebFOCUS question. Link to comment Share on other sites More sharing options...
Roshan Kumar Patra Posted June 9, 2023 Author Share Posted June 9, 2023 Thanks for letting me know. i updated the tags Link to comment Share on other sites More sharing options...
Roshan Kumar Patra Posted June 9, 2023 Author Share Posted June 9, 2023 Thank you for pointing me in right direction. Your recommendation worked and i was able to create the solution perfectly Link to comment Share on other sites More sharing options...
Fredrik Rosell Posted June 9, 2023 Share Posted June 9, 2023 Great - thank you for confirming that! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now