Get File Modification Time? - page 2

 
Rosh:

See topic GMT from external Source and msdn ( FileTimeToSystemTime )


//+------------------------------------------------------------------+
//|                                                CheckFindFile.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
 
#property show_inputs
 
#import "kernel32.dll"
int  FindFirstFileA(string path, int& answer[]);
bool FindNextFileA(int handle, int& answer[]);
bool FindClose(int handle);
bool FileTimeToSystemTime(int ft[],int & st[]);
int  GetTimeZoneInformation(int& TZInfoArray[]);
#import
 
int    nYear,nMonth,nDay,nHour,nMin,nSec,nMilliSec;
int    TZInfoArray[43];
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int LP[82];
   int FileTime[2];
   int SystemTime[4];
   int gmt_shift=0;
   int ret=GetTimeZoneInformation(TZInfoArray);
   if(ret!=0) gmt_shift=TZInfoArray[0];
   Print("Difference between your local time and GMT is: ",gmt_shift," minutes");
   if(ret==2) 
      {
      Print("ret=2");
      gmt_shift+=TZInfoArray[42];
      }
   Print("Current difference between your local time and GMT is: ",gmt_shift," minutes");
   
   int handle = FindFirstFileA(TerminalPath() + "\experts\*.mq4",LP);
   //Print("error = ", GetLastError());
   Print(bufferToString(LP));
   FileTime[0] = LP[1];
   FileTime[1] = LP[2];
   if (FileTimeToSystemTime(FileTime,SystemTime))
      {
      //---- parse date and time from array
         nYear=SystemTime[0]&0x0000FFFF;
         nMonth=SystemTime[0]>>16;
         nDay=SystemTime[1]>>16;
         nHour=SystemTime[2]&0x0000FFFF;
         nMin=SystemTime[2]>>16;
         nSec=SystemTime[3]&0x0000FFFF;
      //---- format date and time items
         string time_string=FormatDateTime(nYear,nMonth,nDay,nHour,nMin,nSec);
         Print("File created at: ",time_string);
 
         datetime local_time=StrToTime(time_string);
         Print("Corrected creation time is: ",TimeToStr(local_time-gmt_shift*60,TIME_DATE|TIME_SECONDS));
 
      }
   ArrayInitialize(LP,0);
/*
   while (FindNextFileA(handle,LP))
      {
      Print(bufferToString(LP));
      ArrayInitialize(LP,0);
      }
*/
   if (handle>0) FindClose(handle);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string FormatDateTime(int nYear,int nMonth,int nDay,int nHour,int nMin,int nSec)
  {
   string sMonth,sDay,sHour,sMin,sSec;
//----
   sMonth=100+nMonth;
   sMonth=StringSubstr(sMonth,1);
   sDay=100+nDay;
   sDay=StringSubstr(sDay,1);
   sHour=100+nHour;
   sHour=StringSubstr(sHour,1);
   sMin=100+nMin;
   sMin=StringSubstr(sMin,1);
   sSec=100+nSec;
   sSec=StringSubstr(sSec,1);
//----
   return(StringConcatenate(nYear,".",sMonth,".",sDay," ",sHour,":",sMin,":",sSec));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
string bufferToString(int buffer[])
   {
   string text="";
   
   int pos = 10;
   for (int i=0; i<64; i++)
      {
      pos++;
      int curr = buffer[pos];
      text = text + CharToStr(curr & 0x000000FF)
         +CharToStr(curr >> 8 & 0x000000FF)
         +CharToStr(curr >> 16 & 0x000000FF)
         +CharToStr(curr >> 24 & 0x000000FF);
      }
   return (text);
   }  
//+------------------------------------------------------------------+

Hi Rosh

Much appreciated for you help, I tried your script to query the Find File.ex4 itself,the result is different from what the file properties shown, kindly see the attched JPG for your information. So I m wondering what could be wrong

Thanks a lot

Tom

 
TT_FX1:
Rosh:

See topic GMT from external Source and msdn ( FileTimeToSystemTime )


//+------------------------------------------------------------------+
//|                                                CheckFindFile.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
 
#property show_inputs
 
#import "kernel32.dll"
int  FindFirstFileA(string path, int& answer[]);
bool FindNextFileA(int handle, int& answer[]);
bool FindClose(int handle);
bool FileTimeToSystemTime(int ft[],int & st[]);
int  GetTimeZoneInformation(int& TZInfoArray[]);
#import
 
int    nYear,nMonth,nDay,nHour,nMin,nSec,nMilliSec;
int    TZInfoArray[43];
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int LP[82];
   int FileTime[2];
   int SystemTime[4];
   int gmt_shift=0;
   int ret=GetTimeZoneInformation(TZInfoArray);
   if(ret!=0) gmt_shift=TZInfoArray[0];
   Print("Difference between your local time and GMT is: ",gmt_shift," minutes");
   if(ret==2) 
      {
      Print("ret=2");
      gmt_shift+=TZInfoArray[42];
      }
   Print("Current difference between your local time and GMT is: ",gmt_shift," minutes");
   
   int handle = FindFirstFileA(TerminalPath() + "\experts\*.mq4",LP);
   //Print("error = ", GetLastError());
   Print(bufferToString(LP));
   FileTime[0] = LP[1];
   FileTime[1] = LP[2];
   if (FileTimeToSystemTime(FileTime,SystemTime))
      {
      //---- parse date and time from array
         nYear=SystemTime[0]&0x0000FFFF;
         nMonth=SystemTime[0]>>16;
         nDay=SystemTime[1]>>16;
         nHour=SystemTime[2]&0x0000FFFF;
         nMin=SystemTime[2]>>16;
         nSec=SystemTime[3]&0x0000FFFF;
      //---- format date and time items
         string time_string=FormatDateTime(nYear,nMonth,nDay,nHour,nMin,nSec);
         Print("File created at: ",time_string);
 
         datetime local_time=StrToTime(time_string);
         Print("Corrected creation time is: ",TimeToStr(local_time-gmt_shift*60,TIME_DATE|TIME_SECONDS));
 
      }
   ArrayInitialize(LP,0);
/*
   while (FindNextFileA(handle,LP))
      {
      Print(bufferToString(LP));
      ArrayInitialize(LP,0);
      }
*/
   if (handle>0) FindClose(handle);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string FormatDateTime(int nYear,int nMonth,int nDay,int nHour,int nMin,int nSec)
  {
   string sMonth,sDay,sHour,sMin,sSec;
//----
   sMonth=100+nMonth;
   sMonth=StringSubstr(sMonth,1);
   sDay=100+nDay;
   sDay=StringSubstr(sDay,1);
   sHour=100+nHour;
   sHour=StringSubstr(sHour,1);
   sMin=100+nMin;
   sMin=StringSubstr(sMin,1);
   sSec=100+nSec;
   sSec=StringSubstr(sSec,1);
//----
   return(StringConcatenate(nYear,".",sMonth,".",sDay," ",sHour,":",sMin,":",sSec));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
string bufferToString(int buffer[])
   {
   string text="";
   
   int pos = 10;
   for (int i=0; i<64; i++)
      {
      pos++;
      int curr = buffer[pos];
      text = text + CharToStr(curr & 0x000000FF)
         +CharToStr(curr >> 8 & 0x000000FF)
         +CharToStr(curr >> 16 & 0x000000FF)
         +CharToStr(curr >> 24 & 0x000000FF);
      }
   return (text);
   }  
//+------------------------------------------------------------------+

Hi Rosh

Much appreciated for you help, I tried your script to query the Find File.ex4 itself,the result is different from what the file properties shown, kindly see the attched JPG for your information. So I m wondering what could be wrong

Thanks a lot

Tom


Testing

 

tradeigel wrote:
well...I think I am seeing what you mean, at least a little. I guess it's a little like the openSourcePhilosophy. I am using Linux so I like this idea ;) But how do you really imagine doing this?

OK - is a.m. I fresh and fit to rant (as usual - lol)

You what??? using *nix! Fantastic..... Please do tell ALL and not spare any of the gory details !

For instance - I have Debian on old ~700MHz box and on Laptop and on main desktop have Ubuntu/Debian on separate partition etc. with grub loader (still though, I refuse to change default menu.lst boot order to linux as default until feel comfortable with putting gun to windoz's head -lol) Have Wine 1.0-rc2 and as bit of giggle installed an ap called WineDoors - just a layer btwn user and Wine really... Anyway, having 'installed' MT one then sees that the help functionality is not gonna work without some kicking... This is where I am presently. Not spend much time due to other work. Think I'll uninstall WineDoors and start afresh with an Alpari MT .exe and get back to basics regards no fluff btwn me and Wine. All the extra layers somehow for me anyway, just add that extra complication that makes 'issue' solving harder...

So ok then, do you use MT on Linux? (and... do U use live a/c?)

Do you have Editor context sensitive help etc...

Fonts ok?

What Linux and windoz emulation pkg using?

...

u know, the complete enviornment and how got going!

I'd drop the windoz program without second thought for the chance to use a real Operating System 24/7...

btw - for those diehard MS types - smiles 2 u: your choice to use what you use... ;o)

==============

Yes, openSource idea.

Put it this way - I believe that MetaQuotes forum functionality prohibits in so many ways. Just look at other forums, the top level is like series of chapter headings eg, First Steps, FX, Stocks, Widgets,... Each of these chapters can now be considered their own forum and if reqd, further top levels/chapters unique to this lower level forum

Why? Well... if was possible, the MT forum could have a subforum/chapter with sections within. The subforum is eg: TIPS, BEST PRACTICES and within this are sections on eg: Expert Advisors, Scripts, Indicators and finally why not have sections within the sections ....

Why? This site has MASSIVE amount of info, yes? Problem is - finding it! tell me, why is it that many posters always ask the same simple questions over and over again?

Answers are many: lazy, not know English well enough to enable confidence in searching etc, not make effort to dig a little,....

Guess what? Often, the questions do get answered, over and over and over again!

Worse still - the answers are virtually the same every time, yes?

eg, how 'know' when one bar finishes and new bar starts - man... that is soooo frequent a post!

eg, I know little or nothing about programming and... btw - I have some killer ideas and wanna just tweak (lol) this EA/script/indicator I just happen to have.... (like this is a site for programming tutorial???) - well... maybe it is, in the shape and form of the MQL4 BOOK! (I maintain that book and like material should be in own chapter...)

on and on one can go.

Basically, this forum has info but it hides info too! If it had more modern? functionality that is generally seen everywhere a forum can be found - then guess what? the forum magically becomes usable for all types and... making a big assumption here! if sensibly organized and additionally and most importantly of all - information can be placed in it's appropriate 'section'

So look - your dll/win/... issues, man... that info is scattered all over this site (I not even gonna dig to prove it but is fact - is all there!) but... Where?

Imagine being able to drill down through forum chapters/subchapters/sections/... and POW! there you are - in a section entitled HOW TO USE WINDOWS API FUNCTIONS or whatever...

Getting idea? complete blow by blow info on how to I/F with api code, tips, code snippets, knowledgebase posts on 'why' one must do this 'n that and why not further reading links thread... the works 'n don't spare the mayo! :)

Would not the above be a great turn on? I'd certainly xxxx for such a forum setup.

The current 'we have a nifty search syntax' to use on our sites search box... Hey... THAT type of functionality otta be available in every chapter/subchapter/section/... and ability to ONLY SEARCH IN THIS AREA <--- so massively important.

The current setup not make muster imho

So many other forums out there whereby one can drill down to find a section devoted totally to the particular area researching... is a no brainer really :o))

So plea for info sharing? Ha! Like blowin in the wind - with current setup.

You post the most amazing relevant earth shattering mind blowing info and... within hours or couple days the post will have scrolled way back (umm, not talkin bout any of my posts hasten to ad :)

going back to sleep now...

best place for old tyme IT people with dementia !

:o)))

 

Hey Ukt,


you're so right! Now that you say it one can see that this actually is not a real forum but something like a ticketSupportThingy, you can just post you request it will be answered (which actually works pretty well, btw) and then it's gone - it's nothing like you imagine, you visionary ;)

 
Ukt, for talking about Linux we should use some more private way of communication like IM or such for not bugging the others with Offtopic stuff in this thread.
 
tradeigel:
Ukt, for talking about Linux we should use some more private way of communication like IM or such for not bugging the others with Offtopic stuff in this thread.

IM is beyond me, sorry bout that - am just ditch digger so all this modern comms stuff goes over me head!

ukttku AT gmail DOT com

ok?

really looking forwards to hearing those gory *nix details!

 

Strange... have attempted in various threads to edit my post. us oldies need sooo much think time - which usually occurs after make the damn post..

Oh merde!

I seem to remember? reading recently about others having forum I/F issues

Others?

 

Hi Rosh

After trying to modify your sample code a bit and also studied the data structure returned by FindFirstFileA() function call, I understand that I have to make the following change

/-------------------------------------------------/

FileTime[0] = LP[1]; FileTime[1] = LP[2];

TO

FileTime[0] = LP[3]; FileTime[1] = LP[4];

/------------------------------------------------/

for accessing the last access time of the file, and FileTime[0] = LP[5]; FileTime[1] = LP[6] for accessing the last modification date of the file.

But all the timing information returns is in "system Time format" . I tried to replace "FileTimeToSystemTime(FileTime,SystemTime)" to "FileTimeToLocalTime(FileTime,SystemTime)" in the code,

but it doesn't work, it shows invalid time.

Do you know what else I have to change to get the exactly same time information that we can obtain from file properties.

Thanks

Tom