question

Vinay S avatar image
0 Likes"
Vinay S asked Jason Lightfoot edited

Get file Modified date

Hello,

I'm uploading a CSV file to Flexsim Model using importtable(),

I need to get that CSV file Modified Date.

I need to print that date and time in the reports.

Someone guide me how to fetch CSV file Modified Date.


Highlighted in the below image: 1695725718943.png

FlexSim 23.0.7
get csv file modified date
1695725718943.png (6.1 KiB)
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jason Lightfoot avatar image Jason Lightfoot ♦♦ commented ·
Can't you add it as a field in the csv?
0 Likes 0 ·
Vinay S avatar image Vinay S Jason Lightfoot ♦♦ commented ·
No that CSV file is generated by third part application. Model will automatically imports the CSV file. The model is scheduled to run every 24hrs. There is no any manual intervention.
0 Likes 0 ·

1 Answer

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Jason Lightfoot edited

If you have Python installed you can create a simple function to return this to a FlexSim user command.

If not you can try reading a text file that you create via something like this FlexScript:

runprogram("cmd /c \"wmic DataFile where Name='E:\\\\myfile.txt' get LastModified /VALUE | find /v \"\" > moddt.txt\"");

which will create moddt.txt containing something like:

LastModified=20010905220058.000000+060
· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Vinay S avatar image Vinay S commented ·

I tried like this,

runprogram("cmd /c \"wmic DataFile where Name='"+getfilebrowse("*.csv","CSV")+"' get LastModified /VALUE > moddt.txt\"");

After selecting the csv file, it generated a moddt.txt, but there is no any data inside moddt.txt. pls check this image.

1695731243077.png

0 Likes 0 ·
1695731243077.png (12.9 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Vinay S commented ·

That won't give you enough escape characters. For your test use:

string filestring=getfilebrowse("*.csv","CSV").replace("\\","\\\\",1);
runprogram("cmd /A /c \"wmic DataFile where Name='"+filestring+"' get LastModified /VALUE | find /v \"\" > moddt.txt\"");
if (fileopen("moddt.txt","r")){
    string line=filereadline();
    line=filereadline();
    line=filereadline();
    fileclose();
    return line;
}
return "failed to open file";

Update: Altered to output UTF-8 text file and return the 3rd line in the file.

0 Likes 0 ·
Vinay S avatar image Vinay S Jason Lightfoot ♦♦ commented ·

I'm using like this, without await its fetching csv before date being entered.

And one more question, why the data is written to 5th row, even if we write it to txt, it writes to 5th line.

runprogram("cmd /A /c \"wmic DataFile where Name='D:\\\\FlexSAP\\\\ZPPC.csv' get LastModified /VALUE | find /v \"\" > date.csv\"");
await Delay.seconds(5);
importtable(Table("date"),"D:\\FlexSAP\\date.csv");
string abc = Table("date")[5][1];
Table("date").setSize(0,0);
print(abc);

If I run model to run in high speed. it won't fetch the updated data from date.csv.

So, I created a php page to get ModifiedDate of file and I'm using applicationcommand("sendhttprequest") to get date.


Thanks for your support.

0 Likes 0 ·
Show more comments