time_create, time_access, etc...

R

red_hax0r

I've been working on a directory listing program and I want to add
things like time_create to it...

\\-------------------------------------
#include <io.h>
#include <stdio.h>
#include <string.h>
int i = 0;
int m=0;
char filelist[100][100];

struct _finddata_t fd;


int main() {
long fh = _findfirst("*.*", &fd);


if (fh != -1) {


do {


if (fd.attrib & _A_SUBDIR);


else sprintf(filelist[i++], "%i", fd.time_create);

}
while (_findnext(fh, &fd) == 0);

m=i;
for (i=0; i < m; i++) printf("%s\n", filelist);
system("pause");
_findclose(fh);
}
return 0;
}


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

This lists out the dates and times of all the files in a certain
format, which I cannot convert.
It took me a while to work out a program in gcc. If you can help me
with any examples, it would be appreciated.
 
F

Flash Gordon

I've been working on a directory listing program and I want to add
things like time_create to it...

\\-------------------------------------
#include <io.h>

Non-standard header, we only deal with standard C here, not
implementation specific extensions.
#include <stdio.h>
#include <string.h>
int i = 0;
int m=0;

Why are these global variables? I can see no good reason, so they should
have been declared inside main. If there is a good reason for them to be
globals then you should chose meaningful longer names.
char filelist[100][100];

Why 100 by 100? I see nothing below to stop you from having more than
100 files, and I doubt that it is possible for the string representation
of an int to be anywhere near 99 characters long.
struct _finddata_t fd;

_finddata_t is non-standard.
int main() {

If you are not using the parameters to main it is better to be explicit.
int main(void) {
long fh = _findfirst("*.*", &fd);

if (fh != -1) {

do {

if (fd.attrib & _A_SUBDIR);

else sprintf(filelist[i++], "%i", fd.time_create);

If the directory has more than 100 entries this is going to go bang.
}
while (_findnext(fh, &fd) == 0);

m=i;
for (i=0; i < m; i++) printf("%s\n", filelist);
system("pause");
_findclose(fh);
}
return 0;
}

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

This lists out the dates and times of all the files in a certain
format, which I cannot convert.
It took me a while to work out a program in gcc. If you can help me
with any examples, it would be appreciated.


Standard C does not know anything about directories or the _finddata_t
struct. I suggest you try asking in a group dedicated to whatever OS you
are using.
 
B

Ben Pfaff

I've been working on a directory listing program and I want to add
things like time_create to it...
[...]

This lists out the dates and times of all the files in a certain
format, which I cannot convert.

The program you included is Windows or MS-DOS specific, so you'd
be better off asking in a newsgroup that focuses on one of those
operating systems.
 
S

SM Ryan

# else sprintf(filelist[i++], "%i", fd.time_create);

# This lists out the dates and times of all the files in a certain

If these date-times are in the same form as what time()
returns (you'll need to check the system specific documentation),
you can use localtime, strftime, and related functions
to convert to the gregorian calendar for output.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,001
Messages
2,570,250
Members
46,848
Latest member
Graciela Mitchell

Latest Threads

Top