f



Comparing file creation/mod dates

I am having this weird problem and hope someone can shed some light on 
it.  I created a program that is supposed to check the file modification 
dates of a program on our network to the date of a file on a 
workstation.  If the date of the file on the server is greater than the 
workstation, the file will be copied and ran.  This file is for updating 
virus definitions.

The only problem is that I can't get the program to behave properly. 
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>

struct stat sb1;
struct stat sb2;

int main (void)
{
   //File on workstation
   if (stat("c:\\program files\\nav\\navup.exe", &sb1) == 0)
   {
	printf("Last modified: %s\n", ctime(&sb1.st_mtime));
   }

   //File on server
   if (stat("f:\\navup.exe", &sb2) == 0)
   {
	printf("Last modified: %s\n", ctime(&sb2.st_mtime));
   }

   if (&sb2.st_mtime > &sb1.st_mtime)
   {
   	chdir("c:\\progra~1\\nav");
   	system("copy f:\\navup.exe C:\\Progra~1\\NAV\\navup.exe");
   	system("c:\\progra~1\\nav\\navup.exe");
   }

   return 0;
}

The problem seem to be with the third IF statement.  If the file dates 
match, the true part of the if statement runs when it should only run if 
the server file has a greater date.

I am  using the Borland C++ 5.02 under Windows XP and Windows 2000 server.

Any ideas?

Dave

0
not137 (2)
9/16/2003 8:54:03 PM
comp.programming 11491 articles. 2 followers. Post Follow

2 Replies
2336 Views

Similar Articles

[PageSpeed] 26

#    if (&sb2.st_mtime > &sb1.st_mtime)

# The problem seem to be with the third IF statement.  If the file dates 
# match, the true part of the if statement runs when it should only run if 
# the server file has a greater date.

You're comparing the address of sb2.st_mtime to the address of sb1.st_mtime.

I strongly suspect you want
     if (sb2.st_mtime > sb1.st_mtime)
which compares the modification times.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
I think that's kinda of personal; I don't think I should answer that.
0
derkgwen (343)
9/16/2003 9:04:04 PM
Thanks so much.  It has been a while since I used C.  I didn't realize 
that I was using the address instead of the value because of the 
'address of' character.


Derk Gwen wrote:
> #    if (&sb2.st_mtime > &sb1.st_mtime)
> 
> # The problem seem to be with the third IF statement.  If the file dates 
> # match, the true part of the if statement runs when it should only run if 
> # the server file has a greater date.
> 
> You're comparing the address of sb2.st_mtime to the address of sb1.st_mtime.
> 
> I strongly suspect you want
>      if (sb2.st_mtime > sb1.st_mtime)
> which compares the modification times.
> 
> --
> Derk Gwen http://derkgwen.250free.com/html/index.html
> I think that's kinda of personal; I don't think I should answer that.

0
not137 (2)
9/17/2003 4:42:53 PM
Reply:

Similar Artilces:

mod file time and mod file date format
Hello, I was looking the ZIP file format and am a bit confused about the format for the ZIPTIME and ZIPDATE. <http://www.bsdg.org/SWAG/ARCHIVES/0022.PAS.html> It says that both are DWORDs in MS-DOS format, so presumably 32 bits each. But I thought that the MS-DOS time stamp was 32 bits in total, i.e. for the date and time? I'm obviously confused somewhere, so any help would be appreciated. Thanks -- Jeffrey Spoon Jeffrey Spoon wrote: > > > Hello, I was looking the ZIP file format and am a bit confused about the > format for the ...

How to retrieve the file creation date in program?
Hi, &nbsp; I&nbsp;am writing a vi&nbsp;to find the file in a folder that was created most recently. Anyhow, I was not able to find a system function that allow me to get the creation date of a file. Can you help me to solve the problem? &nbsp; Thanks &nbsp; Yutao ...

how to compare date of file to a fixed date?
Hello, I am trying to find a way to compare a file's mod date to a fixed date in a bourne shell script. Say I have a directory with a bunch of files and I want to echo if the mod date is between Aug 12 and Aug 19. for i in * do echo $i; if [ $i -ot "Aug 19" ] && [ $i -nt "Aug 12" ]; then echo "this file was created between Aug 12 and Aug 19" fi done The above is a rough logic example and I know the "Aug 19" thing won't work but I just can't place my finger on the right way to do this. Any help is greatly...

Demand for a program that'll fix invalid file creation dates?
Some time ago, I had a dead battery in one of my iMacs, which caused the system clock to become screwy. As it happens, I did a major overhaul to my Web site that day, and so ended up with almost a hundred files with invalid creation dates. That's a significant annoyance, because I upload files to my Web site by date, and it becomes difficult to synchronize everything when the file dates are wrong. On my way back from a business trip in New york on Wednesday, i was bored on the plane, so i wrote an application which will scan a folder searching for files with bad dates, and fix the dates....

how to test file size and creation date in Bash command file
I have a Bash command file with a for loop to process all the files in a directory. But what I want to do is process only files larger than 1 MB that were created on the day the command file is run. How do I test the file size and file creation date in a Bash command file? Thanks, Jeff On 03/21/2009 05:33 PM, Jeff wrote: > I have a Bash command file with a for loop to process all the files in a > directory. But what I want to do is process only files larger than 1 MB > that were created on the day the command file is run. > > How do I test the file size and file crea...

Comparing File dates
Hi, Is there an easy way to compare file dates in tcl? For example, how can I tell if "FileA" is newer than "FileB" ? TIA, -Tennis In article <9bga409eashr65ju5s92k1c2ose0mgpljd@4ax.com>, <tennis_smith@yahoo.com> wrote: . . . >Is there an easy way to compare file dates in tcl? > >For example, how can I tell if "FileA" is newer than "FileB" ? . . . if {[file mtime FileA] > [file mtime FileB]} do_something There's more to the story. Start there. -- Cameron Laird <claird@phaseit.net> Busine...

Creation date of a file
Hello ! Noob questions : - how can I have the date of creation of a file ? - and how to search files (with find) using date of creation as attribute ? Thanks for any questions ! (and have a good day) tibo <bartol_78SPAMSUXXX@yahoo.com> wrote: > - how can I have the date of creation of a file ? You can make a note of when you make it. > - and how to search files (with find) using date of creation as attribute ? Given that creation date is not a file attribute in unix file systems, you cannot. Is there some difficulty with the man page for find? Perhaps "last modific...

file creation date
Is there any way to display the file creation date? Thank you Smokey oldsmokee@yahoo.com typed (on Fri, May 25, 2007 at 02:27:59PM -0500): | Is there any way to display the file creation date? Nothing in Unix records the date a file was created. -- JP ==> http://www.frappr.com/cusm <== I found cr_time in htino.h along with c_time, a_time, and m_time. Supposedly cr_time is the creation time. Is this not implemented or maybe htino.h is not used for the sco unix inode structure? Smokeyh On Fri, 25 May 2007 15:49:07 -0400, Jean-Pierre Radley <jpr@jpr.com> wrote: >oldsmok...

Creation date of a file
Hi, how I can find the creation date of a file ? Thanks in advance=20 bob123 wrote: > Hi, > > how I can find the creation date of a file ? > > Thanks in advance the nearest you will get is the ctime field revealed by stat, I think. The Natural Philosopher <tnp@invalid.invalid> writes: > bob123 wrote: >> Hi, >> >> how I can find the creation date of a file ? >> >> Thanks in advance > the nearest you will get is the ctime field revealed by stat, I think. ....which is also updated by chmod, chown, rename, unlin...

file creation date
It's so rare I can offer help rather than seek advice from others - Nina, you can do a proc contents on a file and keep the output. One field that will stored is called CRDATE. That should give you what you need. e.g., proc contents noprint data=myfile out=temp; data temp; set temp; if _n_ eq 1; proc print; var crdate; HTH- Deb On Tue, 20 Dec 2005, Deborah Wentworth wrote: > It's so rare I can offer help rather than seek advice from others - > > Nina, you can do a proc contents on a file and keep the output. One field > that will stored is called CRDATE. That s...

File date creation
Hello, I'd like to know the date of creation of a file. I think I must use api calls, but I want to know how. thank-you very much, roby. ...

Variation of "diff -qr" to compare file sizes/dates between file tree?
I created a CD volume that backs up some of my laptop. After some time has past, I'd like to check what files need freshening up i.e. what files on the laptop either have no counterpart on the CD, or which have changed from its counterpart on the CD. I am running Cygwin on Windows 2000, so I have access to unix-like (gnu) commands. I've typically run "diff -qr" to find differences between the file hierarchies on the CD and the hard drive. However, this does a bit-by-bit compare, which is way more intensive than what I'm looking for, and takes way too long. I want to c...

how to filter files by creation date
Hello All, I am trying to to make a script to move all the files that has been created at today's to another folder but my problem is the date format that I receive from the 'os.stat [stat.ST_CTIME]' is different from the one that I receive from the 'datetime.date.today()'. Does someone could help me? Here is my script: import os, stat, time, datetime a= "c:\\" filesys = os.listdir(a) today= datetime.date.today() def get_create_time(a): int_time = os.stat("c:\\")[stat.ST_CTIME] str_time = time.ctime(int_time) return str_time #print f...

getting a files creation date
HI, Using Linux I can get the creation date of a file as below $ date --reference=foo +%y%m%d-%H%M%S 040106-233736 Using Solaris what is the best way to get the date in the same format? /michael In article <wPGKb.45241$dP1.184370@newsc.telia.net>, Michael Laajanen <michael.laajanen.no-spam.@telia.com> wrote: > HI, > > Using Linux I can get the creation date of a file as below > > $ date --reference=foo +%y%m%d-%H%M%S > 040106-233736 > > Using Solaris what is the best way to get the date in the same format? install GNU date to get the formatting y...

How to check file creation date
ls -lt just select the file last updated date. How to check file creation date and time ? -rw-r--r-- 1 itxxx x85 4783481 Feb 8 09:36 1510208_finger_53.prn moon wrote: > ls -lt just select the file last updated date. How to check file creation > date and time ? > -rw-r--r-- 1 itxxx x85 4783481 Feb 8 09:36 1510208_finger_53.prn You can't, it's not recorded. In article <95cGf.54$ms5.4350@ns2.gip.net>, "moon" <moon_ils-se@yahoo.com.hk> wrote: > ls -lt just select the file last updated date. How to check file creation > date and...

Creation date from Solaris file
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi all, I have a little question, how can i see the creation date from a file???? and/or how can i see a lot of information from a file [creation date, mod date, other info]??? Thanks. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFBc8fiWvC4cA0xVH8RAoKhAKCw7Eiicq5UPPfM54eu/EdBBHaGGACgwuTB hrFv5hV6EuOMIFg8GZjqFng= =QEHT -----END PGP SIGNATURE----- On Mon, 18 Oct 2004, macd55 wrote: > how can i see the creation date from a file???? Solaris (nor any other UNIX) doesn't store the creation time. > how can i see...

Change file creation date?
I want to modify the file creation time to syncronize my local dates with the dates on a server. I haven't found any way to do that yet Using File::stat lets me read the file statistics for: meaning of the fields: 0 dev device number of filesystem 1 ino inode number 2 mode file mode (type and permissions) 3 nlink number of (hard) links to the file 4 uid numeric user ID of file's owner 5 gid numeric group ID of file's owner 6 rdev the device identifier (special files only) 7 size total size of file, in by...

Set file creation date
Is there a way to set a file's creation date? I'm getting file dates from a cellphone dated 2040 and my system can't handle it. -- Gnarlie Thus spake Gnarlodious (gnarlodious@yahoo.com): > Is there a way to set a file's creation date? I'm getting file dates from a > cellphone dated 2040 and my system can't handle it. You can't. The "creation date" of a file on a Unix fs (ext2/ext3/etc.) isn't recorded. I suggest that you read the stat(2) manpage, and pay special attention to the explanations of the st_ctime, st_atime, and st_mtime values. The...

Determining file creation date?
Is there a function that determines when a file was created? Like if I wanted to return all the files created in the last month from a directory, is there a way to do that? I've googled and googled but can't find what I'm looking for. Thanks "Matt Traxinger" <MattTrax@yahoo.com> wrote in news:ck1n1b$fqh$1@news-int.gatech.edu: > Is there a function that determines when a file was created? Like if I > wanted to return all the files created in the last month from a > directory, is there a way to do that? I've googled and googled but > can't fin...

FTP file creation date
Hi all, I would like to write a script that downloads one file from a ftp server if the file creation date satisfy a condition. I can't figure out how to find from a ftp server what is the creation date of the file (using python). Any idea? Thanks for your help! EuGeNe [ EuGeNe ] wrote: > Hi all, > > I would like to write a script that downloads one file from a ftp > server if the file creation date satisfy a condition. > > I can't figure out how to find from a ftp server what is the creation > date of the file (using python). > > Any idea? > >...

Date-Time of Program File
Running interactively in Windows, if I get my path and SAS program filename like so: =20 %let PATH =3D %sysget(SAS_EXECFILEPATH); %let PROGRAM =3D %sysget(SAS_EXECFILENAME); =20 is there a way to also get the date time associated with when that program was last saved? ...

Re: file creation date
On Tue, 20 Dec 2005, Deborah Wentworth wrote: > It's so rare I can offer help rather than seek advice from others - > > Nina, you can do a proc contents on a file and keep the output. One field > that will stored is called CRDATE. That should give you what you need. > > e.g., > > proc contents noprint data=myfile out=temp; > > data temp; set temp; if _n_ eq 1; > > proc print; var crdate; Deb, I hope you do not mind a suggestion then :) You have some unnecessary step. Consider: proc print data = temp ( obs = 1 ) ; run ; (Further sophisticat...

How to replace c:\Program Files with Program Files (x86) in all scripts?
Hi experts, I have a parent folder, C:\Test and it has a few sub-folders (and its files) and files and I am now forced to do the following change in all files starting from its parent folder, c:\Test To replace a string, "c:\\program files\" or "c:\PROGRA~1" with "C:\ \Program Files (x86)" in all files. Here is some thing I am trying with: C:\>perl -i.bak -pe "s/Progra~1/Program Files (x86)/g" `find "C:\ \Test" -type f -name "*.pl" ` Error is: Can't open `find: No such file or directory. Can't do inplace edit: C:\\Test...

Getting file creation dates...
Can someone tell me how to get all the file names and their creation dates from a directory? I have the following which only gives me file names: opendir(DIR, ".") or die "Cannot open current directory\n"; my @files = readdir DIR; closedir DIR; Thanks -Ed "Ed Landau" <aunst8_2000@yahoo.com> wrote in message news:UyIQb.17042$CY7.15244@newssvr25.news.prodigy.com... > Can someone tell me how to get all the file names and their creation dates > from a directory? > I have the following which only gives me file names: > > > opendir(DI...

Web resources about - Comparing file creation/mod dates - comp.programming

Forbes.com Removes Post Comparing Facebook COO Sheryl Sandberg To Kim Polese
... Officer Mark Zuckerberg ) as Silicon Valley’s new It girl. That was one thing, and a fine thing. But when the article went beyond, comparing ...

Comparing Tech Companies by Revenue and Profit Per Employee, 2015
Two tweets from Dustin Curtis that tell a big story.

KidZilla - Counting, Comparing, Matching and Rhyming Fun for Kids! on the App Store on iTunes
Get KidZilla - Counting, Comparing, Matching and Rhyming Fun for Kids! on the App Store. See screenshots and ratings, and read customer reviews. ...


YouTube - Bill Hader On Howard Stern Comparing SNL Guest Hosts
You are using an outdated browser, which YouTube no longer supports. Since some features on YouTube may not work, you are viewing a lightweight ...

Comparing Approval Ratings From Different Polling Firms
Rasmussen Reports - The best place to look for polls that are spot on

Getting around Dubai: Comparing taxis, trains and personal cars
A taxi will get you where you need to go quickly, but is it the most cost-effective option for getting around Dubai? A personal car gives you ...

Russia courts backlash in China by comparing Western sanctions to Tiananmen square reaction
The Russian Embassy in Beijing has just committed a large digital diplomacy gaffe, one the size and shape of a certain public square in China's ...

Bob Dylan charged in France after comparing Croatians to Nazis
Paris: French authorities have filed preliminary charges against Bob Dylan over a 2012 interview in which he is quoted comparing Croatians to ...

Snapped: Comparing Nokia Lumia 1020, Samsung GS4 and HTC One camera quality
Nokia's brand-new Lumia 1020 Windows Phone packs one of the most unique phone cameras on the market today. Carl Zeiss Tessar lens; 41MP (forty-one-megapixel) ...

Resources last updated: 2/16/2016 6:17:15 AM