Forum Stats

  • 3,827,879 Users
  • 2,260,836 Discussions
  • 7,897,402 Comments

Discussions

How do you query for File Properties in Windows?

mfanning2010
mfanning2010 Member Posts: 18 Red Ribbon
edited Apr 3, 2018 4:09PM in Data Integrator

Hello,

We are trying to figure out a way of using an OS command within Oracle Data Integrator 12.2.1.3 to query an XML file attribute specifically the Date Modified.

We have an application that outputs an XML file with the same name so we are trying to build out an integration process to pull from the XML file when it is updated. The file exists on Windows Server 2012, but I am not finding much luck on a way of getting the Date Modified field of file properties.

The thought is we would load a variable with the initial date when executing for the first time (OldDate variable), then have a Package that checks the current date modified (loads to a variable CurDate), and if the CurDate > OldDate the integration process would take the XML file data and do a conversion to a SQL Server database for another application to read.

I know if the file included a date/timestamp we could us an ODI Variable to parse the file name as a string to derive the date/timestamp, but that isn't an option in this case.

Any ideas on this?

Thank you,

Matthew Fanning

Tagged:
Pavan8u

Best Answer

  • Adrian_Popescu-Oracle
    Adrian_Popescu-Oracle RomaniaPosts: 1,984 Employee
    edited Apr 3, 2018 3:53PM Answer ✓

    Hi Matthew,

    You can get the Date Modified of a file by using a Jython procedure. The code below you may test on an ODI procedure using Jython technology and will store in file 'D:/output.txt' the Date Modified of file "D:/rezultat.txt".

    The you can use a variable to tranfer the data from file 'D:/output.txt' into a variable, using the code generated by ODI when creating a mapping that reads that file.

    import time, os

    f=open("D:/output.txt","w")

    p=time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime('D:/rezultat.txt')))

    f.write(p)

    f.close()

    Hope this helps,

    Adrian

    Pavan8u

Answers

  • Adrian_Popescu-Oracle
    Adrian_Popescu-Oracle RomaniaPosts: 1,984 Employee
    edited Apr 3, 2018 3:53PM Answer ✓

    Hi Matthew,

    You can get the Date Modified of a file by using a Jython procedure. The code below you may test on an ODI procedure using Jython technology and will store in file 'D:/output.txt' the Date Modified of file "D:/rezultat.txt".

    The you can use a variable to tranfer the data from file 'D:/output.txt' into a variable, using the code generated by ODI when creating a mapping that reads that file.

    import time, os

    f=open("D:/output.txt","w")

    p=time.strftime("%m/%d/%Y %I:%M:%S %p",time.localtime(os.path.getmtime('D:/rezultat.txt')))

    f.write(p)

    f.close()

    Hope this helps,

    Adrian

    Pavan8u
  • mfanning2010
    mfanning2010 Member Posts: 18 Red Ribbon
    edited Apr 2, 2018 5:39PM

    Hello Adrian,

    Thank you for this!

    I created the procedure and it runs successfully, but no results appear in the D:/rezultat.txt file. Any thoughts?

    Matthew Fanning

  • Adrian_Popescu-Oracle
    Adrian_Popescu-Oracle RomaniaPosts: 1,984 Employee
    edited Apr 3, 2018 1:32AM

    Hi Matthew,

    D:/output.txt is the file in which the modification date will be stored (saved).

    D:/rezultat.txt is the source file for which you need the modification date.

    You need to check file D:/output.txt

    I have tested the code and it works.

    You need to amend it for your files and paths.

    Adrian

  • mfanning2010
    mfanning2010 Member Posts: 18 Red Ribbon
    edited Apr 3, 2018 1:14PM

    Oh got it thank you, I misunderstood which file is which.

    I can see the date modified stored in the file.

    Thank you for your assistance!

    Matthew Fanning

  • Adrian_Popescu-Oracle
    Adrian_Popescu-Oracle RomaniaPosts: 1,984 Employee
    edited Apr 3, 2018 3:56PM

    Hi Matthew,

    If you consider your question is answered please mark this post as Answered, in order to help also other customers.

    Adrian

  • mfanning2010
    mfanning2010 Member Posts: 18 Red Ribbon
    edited Apr 3, 2018 4:09PM

    Oh just did, first time using the Oracle Community.

    Thanks again.

    Matthew Fanning

This discussion has been closed.