Link to home
Start Free TrialLog in
Avatar of alibax
alibax

asked on

Date and Time stamp - in C programming language

Hi! I'm trying to make a program in either C/ java/vb  which captures the name of the files/directory date, time of when the files or directory was created, modified, accessed. This data should be stored into a Database. The date and time should be updated when the file is modified; lets say the next day (we going to have a date comparison).  In short, the program should capture the the name of the files/directories,  date and time of files created, date and time of file modified, accessed. I'm a beginner in C/ java language and any start of the process of coding would be appreciated.

Many thanks
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Use a FileMonitor
What OS are you targetting? For Windows, see http://msdn2.microsoft.com/en-us/library/aa365200.aspx ("Listing the Files in a Directory") - the time information then is available for each file using 'GetFileTime()' (http://msdn2.microsoft.com/en-us/library/ms724320.aspx)

For Linux, that would be

#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>

int main(int argc, char **argv)
{
DIR *dirHandle;
struct dirent * dirEntry;
struct stat buf;

  dirHandle = opendir(".");
  if (dirHandle) {
    while (0 != (dirEntry = readdir(dirHandle))) {
        puts(dirEntry->d_name);
        stat(dirEntry->d_name,&buf);
        printf( "Time modified : %s", ctime( &buf.st_atime ) );

    }
    closedir(dirHandle);
  }
}
Avatar of grg99
grg99

The simplest way would be to do a (on Windows)   system ("DIR C: /S /B >foo" ) and on Unix system( "ls -lR / >foo" ), then read in the file "foo".   THen use SQL to create and populate a database.


Or for a little bit more speed, use opendir() readdir() closedir().   Use google "Man readdir" for info.


>>and on Unix system( "ls -lR / >foo" ),

No - you'd have to call stat for the info required
following give a good example and discussion to get you started:

http://www.javaworld.com/javaworld/javatips/jw-javatip125.html
Let me know if you get stuck and I can help you further :)
Avatar of alibax

ASKER

Hi!

Thanks for the responce I'm working on it and i shall get back soon....
Avatar of alibax

ASKER

Sorry Guys for a late reply. I have come back again on this lilttle project. I was wondering before I start coding is there  a model like if i was designing a Database i would think  of Entity Relation Models, context diagrams, DFDs etc and is there some sort of design for a  timestamp? and where is the time/date stored  in windows?..... is it in the file system driver?.  I am trying to understand how it works first before attempting going any further.... any help would be appriciated.

Many thanks
alibax

All of the information is internal to the file system in question. Of course, each different file system has different metadata
Avatar of alibax

ASKER

Hi!

I have managed to get the last modified time, as there is a method for it in File class but not  the other times. I was wondering how will I be able to get the creation and access times ? I have attached a java source code.

Many thanks
Alibax
package timestamp;
import java.io.*;
import java.util.*;
 
public class Main {
 
public static void main(String[] args)throws IOException {
        
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
System.out.println("Enter file or directory name : ");
		
File filename = new File(in.readLine());
// check to see if its a directory
if (filename.isDirectory()){
// check to see if its a file
if (filename.exists()){
long t = filename.lastModified();
// get a directory name
System.out.println("Directory name : " + filename.getName());
                         
System.out.println("Directory modification date and time : " + new Date(t));
}		
else{
System.out.println("Directory not found!");
System.exit(0);
}
}
		
else{   // check to see if the file name exists
if (filename.exists()){
long t = filename.lastModified();
System.out.println("File name : " + filename.getName());
System.out.println("File modification date and time : " + new Date(t));
}
else{
System.out.println("File not found!");
System.exit(0);
}
}
    
    }
}

Open in new window

The problem is that different OSs have different filesystems with different methods of timestamping. You need to call the OS or use JNI to cope with that
Avatar of alibax

ASKER

But most windows have a standard NTFS file system now and the data about time stamp is stored in one the Metafiles (MFT), you would think there will be one conventional way to retrive these files given for all NTFS. And why is there a method to retrive last modified time only and not others times?.  

And JNI? does this mean I will have to write in different language and incooperate it with java??
I know a bit of C but if i knew a lot more then I would use just C. Is there a anotherway in Java?
>>But most windows have a standard NTFS file system now

Yes, but that's *one* OS of many. Java is a cross-platform language ...

>>And why is there a method to retrive last modified time only and not others times?.

I thought i'd explained that above

>>And JNI? does this mean I will have to write in different language and incooperate it with java??

Yes - C/C++

>>Is there a anotherway in Java?

There could be a command line utility for NTFS alone (if that's what you're interested in) that you can execute with Runtime.exec
Avatar of alibax

ASKER

This is so much advance for me. The problem is now I dont know where to begin. I am only trying to display date and times of files in windows by creating a small program which does that but it seems to be a big job from what your saying since I am not advance user. I will read around on C to see if i will be able to implement with!!

Many thanks anyway....
If you're only interested in supporting Windows, try my second suggestion  - it's easier
Avatar of alibax

ASKER

You mean the "java.lang.Runtime.exec()" class ?? I dont know how to start or even use such class! have u got any example where this method was used. That might give me a head start because know I dont know anything at all.. Sorry for the trouble I am still learning the language.
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

But i don't know what utility you'd use. Ask in the XP TA
Avatar of alibax

ASKER

Hi!

The command that is used to retrieve times dir/t* (* = the type of time) for example access time the command will be "dir/ta". I am trying to implement in congestion with a user inputing the name of the directory or file name but this proves difficult.... as it doesnt run .... code attached below:


package timestamp2;
import java.io.*;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException{
	
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			
		//System.out.println("Enter file or directory name in proper format to get the modification date and time : ");
		System.out.println("Please Enter Directory or File Name" );
		File filename = new File(in.readLine());
            
		Runtime rt1= Runtime.getRuntime();
                //creation time
                Process creationtime= rt1.exec(filename + "dir/ta");
               
                //access time
                Process accesstime= rt1.exec(filename+ "dir/ta");
               
                //modified time
                Process modifiedtime= rt1.exec(filename+ "dir/ta");
               
            System.out.println("Creation time: " + accesstime);
            System.out.println("Creation time: " + creationtime);
            System.out.println("Creation time: " + modifiedtime);
                
        }
}	
 
        

Open in new window

You need spaces in those command after dir and you need to read the Process streams. See

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Avatar of alibax

ASKER

Hi! thanks for the response. Now it compiles alright but when I specify a filename or directory name then its gives me an IOException: I have done a bit of research and a lot of articles seem to suggest that the file/directory I have specify is not found. C:\Dev-C++ does exist. Any suggestions?

C:\>java Times
Enter file or directory name:
C:\Dev-C++
exception happened :
java.io.IOException: CreateProcess: "dir \tc" "dir /ta" "dir /twC:\Dev-C++" error=2
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.<init>(Unknown Source)
        at java.lang.ProcessImpl.start(Unknown Source)
        at java.lang.ProcessBuilder.start(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at Times.main(Times.java:23)
import java.io.*;
 
public class Times {
 
    public static void main(String args[]) {
 
        String s = null;
 
        try {
        
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	
        System.out.println("Enter file or directory name: ");
		
        File filename = new File(in.readLine());
        
	    // run windows command in conjuction with entered file/directory name
	    // creation time "dir /tc"
	    // access time    "dir /ta"
	    // modifed time   "dir /tw"
	    String [] times={"dir /tc", "dir /ta" , "dir /tw" + filename};
            
            Process p= Runtime.getRuntime().exec(times);
            //Process p= Runtime.getRuntime().exec("dir /tc" + "dir /ta" + "dir /tw" + filename);
            BufferedReader stdInput = new BufferedReader(new 
                 InputStreamReader(p.getInputStream()));
 
            BufferedReader stdError = new BufferedReader(new 
                 InputStreamReader(p.getErrorStream()));
 
            // read the output from the command
            
            System.out.println("The output:\n");
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }
            
            // read any errors from the attempted command
 
            System.out.println("Here is the standard error of the command (if any):\n");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }
            
            System.exit(0);
        }
        catch (IOException e) {
            System.out.println("exception happened : ");
            e.printStackTrace();
            System.exit(-1);
        }
    }
}

Open in new window

Avatar of alibax

ASKER

I have come across this:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=3
But how can this solve the problem of a user enterting a filename..... is there another way of coding it? to allow a user to enter file/directory name and in a sense it should combine the command and file/directory name and output its times
>>"dir /twC:\Dev-C++"

Is there meant to be no space between /tw and C: ?
Avatar of alibax

ASKER

Even with spaces doesnt work. Any other altenative?

C:\>java Times C:\Dev-C++
exception happened :
java.io.IOException: CreateProcess: dir\tc dir/ta dir/tw C:\Dev-C++ error=2
    String [] times= new String [4];
	      
	      times [0]= "dir/tc";
	      times [1]= "dir/ta";
	      times [2]= "dir/tw";
	      times [3]= args[0];
	     Process p= Runtime.getRuntime().exec(times);

Open in new window

Please post the result of the following command:

dir C:\Dev-C++
Avatar of alibax

ASKER

The result of command dir C:\Dev-C++ :

C:\>dir C:\Dev-C++
 Volume in drive C has no label.
 Volume Serial Number is 20FB-E730

 Directory of C:\Dev-C++

21/01/2008  10:38    <DIR>          .
21/01/2008  10:38    <DIR>          ..
21/01/2008  10:38    <DIR>          Bin
18/01/2008  02:24             2,026 devcpp.ini
               1 File(s)          2,026 bytes
               3 Dir(s)  12,809,760,768 bytes free


Creation time ( "dir/tc " )

C:\>dir/tc C:\Dev-C++
 Volume in drive C has no label.
 Volume Serial Number is 20FB-E730

 Directory of C:\Dev-C++

22/12/2007  21:29    <DIR>          .
22/12/2007  21:29    <DIR>          ..
22/12/2007  21:29    <DIR>          Bin
22/12/2007  21:30             2,026 devcpp.ini
               1 File(s)          2,026 bytes
               3 Dir(s)  12,809,760,768 bytes free

Last access time ( "dir/ta " )

C:\>dir/ta C:\Dev-C++
 Volume in drive C has no label.
 Volume Serial Number is 20FB-E730

 Directory of C:\Dev-C++

09/03/2008  22:01    <DIR>          .
09/03/2008  22:01    <DIR>          ..
09/03/2008  01:25    <DIR>          Bin
18/01/2008  02:24             2,026 devcpp.ini
               1 File(s)          2,026 bytes
               3 Dir(s)  12,809,760,768 bytes free

Modified time  ( "dir/tw " )

C:\>dir/tw C:\Dev-C++
 Volume in drive C has no label.
 Volume Serial Number is 20FB-E730

 Directory of C:\Dev-C++

21/01/2008  10:38    <DIR>          .
21/01/2008  10:38    <DIR>          ..
21/01/2008  10:38    <DIR>          Bin
18/01/2008  02:24             2,026 devcpp.ini
               1 File(s)          2,026 bytes
               3 Dir(s)  12,809,760,768 bytes free

>>String [] times={"dir /tc", "dir /ta" , "dir /tw" + filename};

should be

String [] times={"dir /tc", "dir /ta" , "dir /tw " + filename};
Avatar of alibax

ASKER

Both of the statements are the same.......  no differences from the first one
They're not - look at the spacing with a large font
Avatar of alibax

ASKER

It doesnt work I still get the  IOException error 2 when I run it & enter filename/directory name.  Does it work on yours?. Why cant I just create my own class without using  Run exe() or JNI? is this possible if so how can I go about it because I cant see how this can be done.
I can't test it at the moment - i'm not running Windows. Print out the command that you're executing. Can you execute the exact same command at the command line?
Broadly, there are two things wrong:

a. The command looks wrong. Normally dir is only run once per command - you have it several times
b. The Process' streams need to be treated on separate threads. See

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Avatar of alibax

ASKER

I agree with you that the command isnt in the right format as it wouldnt even run expectedly under Dos. But how can you execute multiple commands? that wold mean you will need different processes and input and output streams as well.... otherwise it will through a compile error as already defined. Surely there must be a way apart from creating different processes and I/O streams to execute these command. I was going to hold these commands in an array but in principle the process still executes more than command so it doesnt makes a difference. Unless there is another way to execute multiple commands without using different processes &  I/O Stream.

Apart from using JNI or run exe()...... is there another way?? By the look of it I am chasing the air for something that could have been much simpler.
You could do

dir C:\ && dir C:\Dev-C++
Avatar of alibax

ASKER

Hi! Sorry for late reply. The problem is still there when you combine commands together or when you use only one command. When you use single command in Dos works fine but when you coded it in your code it doesn't work. I have done a bit of search and I have come across a filetimes class which is part of JNI.  By the use of this class will allow you to set/get those times. The problem is I have read some tutorials on JNI online but they don't make sense at all.... The class and JNI is already written the only thing I have to do is to make use of it i.e. create methods which gets the times. The problem is how do I set the path in order for my code  to integrate with the filetimes class + JNI ??  The JNI is still new and I have no ideal how to make use of it.

The file times class & JNI can be found here:  http://mindprod.com/zips/filetimes18.zip

The code I have written is attached and the error I am getting is : "package com.Desktop.Forensic_project.com.mindprod does not exist".  I have save the file  mactime.java in  C:\Documents and Settings\com\Desktop\Forensic_project\com\mindprod\filetimes. This is where the filetimes class & JNI exist.... I guess its the path problem or?

Many thanks!!


import com.Desktop.Forensic_project.com.mindprod.filetimes;
import java.io.*;
import java.util.*;
 
public class mactime{
	public static void main(String[] args) throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("Please Enter a File/Directory name: ");
		File filename = new File(in.readLine());
		if (filename.isDirectory()){
			if (filename.exists()){
			
			long current = System.currentTimeMillis();
			long lastAccessed = filename.getFileLastAccessed();
				
				System.out.println("File name : " + filename.getName());
				System.out.println("File Last access date and time : " + new Date(lastAccessed));
				
				long created = filename.getFileCreated();
				System.out.println("File name : " + filename.getName());
				System.out.println("File creation date and time : " + new Date(created));
				
				
				long lastModified = FileTimes.getFileLastModified();
				System.out.println("File name : " + filename.getName());
				System.out.println("File last modification date and time : " + new Date(lastModified));
			}
			else{
				System.out.println("Directory not found!");
				System.exit(0);
			}
		}
		else{
			if (filename.exists()){
				long current = System.currentTimeMillis();
				long lastAccessed = filename.getFileLastAccessed();
				
				System.out.println("File name : " + filename.getName());
				System.out.println("File Last access date and time : " + new Date(lastAccessed));
				
				long created = filename.getFileCreated();
				System.out.println("File name : " + filename.getName());
				System.out.println("File creation date and time : " + new Date(created));
				
				
				long lastModified = FileTimes.getFileLastModified();
				System.out.println("File name : " + filename.getName());
				System.out.println("File last modification date and time : " + new Date(lastModified));
				
			}
			else{
				System.out.println("File not found!");
				System.exit(0);
			}
		}
	}
}

Open in new window

Add that zip file to your class path and do your imports as below:
import com.mindprod.filetimes.*;
import com.mindprod.common11.*;

Open in new window

Avatar of alibax

ASKER

This is what I have done to set the class path:   My computer > properties>advanced>Environment Variables> class path in a User variables & System variables.

User variables- class path  as : C:\Program Files\Java\jdk1.5.0_09\bin;C:\Documents and Settings\com\My Documents\filetimes18.zip

System variable- class path as : .;C:\Program Files\Java\jdk1.5.0_09\bin;C:\Program Files\Java\jre1.5.0_09\lib\ext\QTJava.zip;C:\Documents and Settings\com\My Documents\filetimes18.zip

But I still get the same error message:

mactime.java:1: package com.mindprod.filetimes does not exist
import com.mindprod.filetimes.*;
^
mactime.java:2: package com.mindprod.common11 does not exist
import com.mindprod.common11.*;
^

What have I done wrong?
Can you do

echo %CLASSPATH%

at the command line?
Avatar of alibax

ASKER

C:\Documents and Settings\com>echo %CLASSPATH%
C:\Program Files\Java\jdk1.5.0_09\bin;C:\Documents and Settings\com\My Documents
\filetimes18.zip
OK and now the following two please:

dir "C:\Documents and Settings\com\My Documents\filetimes18.zip"

jar tf "C:\Documents and Settings\com\My Documents\filetimes18.zip"
Avatar of alibax

ASKER

C:\Documents and Settings\com>dir "C:\Documents and Settings\com\My Documents\filetimes18.zip"
 Volume in drive C has no label.
 Volume Serial Number is 20FB-E730

 Directory of C:\Documents and Settings\com\My Documents

11/03/2008  19:47           641,462 filetimes18.zip
               1 File(s)        641,462 bytes
               0 Dir(s)  12,893,298,688 bytes free
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - -

C:\Documents and Settings\com>jar tf "C:\Documents and Settings\com\My Documents\filetimes18.zip"
com/mindprod/filetimes/DESCRIPT.ION
com/mindprod/filetimes/FileTimes.class
com/mindprod/filetimes/FileTimes.java
com/mindprod/filetimes/OnlyDirsFilter.class
com/mindprod/filetimes/TouchDirs.class
com/mindprod/filetimes/TouchDirs.java
com/mindprod/filetimes/build.xml
com/mindprod/filetimes/desc.btm
com/mindprod/filetimes/filetimes.jar
com/mindprod/filetimes/filetimes.look
com/mindprod/filetimes/filetimes.use
com/mindprod/filetimes/filetimes.xml
com/mindprod/filetimes/filetimesicon128.png
com/mindprod/filetimes/filetimesicon16.png
com/mindprod/filetimes/filetimesicon32.png
com/mindprod/filetimes/filetimesicon48.png
com/mindprod/filetimes/filetimesicon64.png
com/mindprod/filetimes/filetimespaddesc.html
com/mindprod/filetimes/filetimesscreenshot.png
com/mindprod/filetimes/javadoc/allclasses-frame.html
com/mindprod/filetimes/javadoc/allclasses-noframe.html
com/mindprod/filetimes/javadoc/com/mindprod/filetimes/FileTimes.html
com/mindprod/filetimes/javadoc/com/mindprod/filetimes/TouchDirs.html
com/mindprod/filetimes/javadoc/com/mindprod/filetimes/class-use/FileTimes.html
com/mindprod/filetimes/javadoc/com/mindprod/filetimes/class-use/TouchDirs.html
com/mindprod/filetimes/javadoc/com/mindprod/filetimes/package-frame.html
com/mindprod/filetimes/javadoc/com/mindprod/filetimes/package-summary.html
com/mindprod/filetimes/javadoc/com/mindprod/filetimes/package-tree.html
com/mindprod/filetimes/javadoc/com/mindprod/filetimes/package-use.html
com/mindprod/filetimes/javadoc/constant-values.html
com/mindprod/filetimes/javadoc/deprecated-list.html
com/mindprod/filetimes/javadoc/help-doc.html
com/mindprod/filetimes/javadoc/index-all.html
com/mindprod/filetimes/javadoc/index.html
com/mindprod/filetimes/javadoc/overview-tree.html
com/mindprod/filetimes/javadoc/resources/inherit.gif
com/mindprod/filetimes/javadoc/stylesheet.css
com/mindprod/filetimes/nativefiletimes/DESCRIPT.ION
com/mindprod/filetimes/nativefiletimes/Debug/BuildLog.htm
com/mindprod/filetimes/nativefiletimes/Debug/nativefiletimes.dll
com/mindprod/filetimes/nativefiletimes/Release/BuildLog.htm
com/mindprod/filetimes/nativefiletimes/Release/DESCRIPT.ION
com/mindprod/filetimes/nativefiletimes/Release/nativefiletimes.dll
com/mindprod/filetimes/nativefiletimes/filetimes.c
com/mindprod/filetimes/nativefiletimes/filetimes.h
com/mindprod/filetimes/propdll.bat
com/mindprod/filetimes/rebuild.xml
com/mindprod/filetimes/run.bat
com/mindprod/filetimes/touchdirs.jar
com/mindprod/filetimes/use.txt
com/mindprod/filetimes/version.txt
com/mindprod/common11/BigDate.class
com/mindprod/common11/BigDate.java
com/mindprod/common11/Build.class
com/mindprod/common11/Build.java
com/mindprod/common11/CMPAboutBox$1.class
com/mindprod/common11/CMPAboutBox$2.class
com/mindprod/common11/CMPAboutBox$3.class
com/mindprod/common11/CMPAboutBox$4.class
com/mindprod/common11/CMPAboutBox.class
com/mindprod/common11/CMPAboutBox.java
com/mindprod/common11/Common11.class
com/mindprod/common11/Common11.java
com/mindprod/common11/DESCRIPT.ION
com/mindprod/common11/Hybrid$1.class
com/mindprod/common11/Hybrid.class
com/mindprod/common11/Hybrid.java
com/mindprod/common11/ImageInfo.class
com/mindprod/common11/ImageInfo.java
com/mindprod/common11/ImageViewer.class
com/mindprod/common11/ImageViewer.java
com/mindprod/common11/Limiter.class
com/mindprod/common11/Limiter.java
com/mindprod/common11/Misc.class
com/mindprod/common11/Misc.java
com/mindprod/common11/ResizingImageViewer.class
com/mindprod/common11/ResizingImageViewer.java
com/mindprod/common11/Shuffle.class
com/mindprod/common11/Shuffle.java
com/mindprod/common11/StoppableThread.class
com/mindprod/common11/StoppableThread.java
com/mindprod/common11/StringTools.class
com/mindprod/common11/StringTools.java
com/mindprod/common11/TestDate.class
com/mindprod/common11/TestDate.java
com/mindprod/common11/VersionCheck.class
com/mindprod/common11/VersionCheck.java
com/mindprod/common11/build.xml
com/mindprod/common11/common11.jar
com/mindprod/common11/common11.look
com/mindprod/common11/common11.use
com/mindprod/common11/common11.xml
com/mindprod/common11/common11icon128.png
com/mindprod/common11/common11icon16.png
com/mindprod/common11/common11icon32.png
com/mindprod/common11/common11icon48.png
com/mindprod/common11/common11icon64.png
com/mindprod/common11/common11paddesc.html
com/mindprod/common11/common11screenshot.png
com/mindprod/common11/desc.btm
com/mindprod/common11/javadoc/allclasses-frame.html
com/mindprod/common11/javadoc/allclasses-noframe.html
com/mindprod/common11/javadoc/com/mindprod/common11/BigDate.html
com/mindprod/common11/javadoc/com/mindprod/common11/Build.html
com/mindprod/common11/javadoc/com/mindprod/common11/CMPAboutBox.html
com/mindprod/common11/javadoc/com/mindprod/common11/Common11.html
com/mindprod/common11/javadoc/com/mindprod/common11/Hybrid.html
com/mindprod/common11/javadoc/com/mindprod/common11/ImageInfo.html
com/mindprod/common11/javadoc/com/mindprod/common11/ImageViewer.html
com/mindprod/common11/javadoc/com/mindprod/common11/Limiter.html
com/mindprod/common11/javadoc/com/mindprod/common11/Misc.html
com/mindprod/common11/javadoc/com/mindprod/common11/ResizingImageViewer.html
com/mindprod/common11/javadoc/com/mindprod/common11/Shuffle.html
com/mindprod/common11/javadoc/com/mindprod/common11/StoppableThread.html
com/mindprod/common11/javadoc/com/mindprod/common11/StringTools.html
com/mindprod/common11/javadoc/com/mindprod/common11/TestDate.html
com/mindprod/common11/javadoc/com/mindprod/common11/VersionCheck.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/BigDate.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/Build.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/CMPAboutBox.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/Common11.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/Hybrid.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/ImageInfo.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/ImageViewer.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/Limiter.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/Misc.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/ResizingImageViewer.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/Shuffle.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/StoppableThread.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/StringTools.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/TestDate.html
com/mindprod/common11/javadoc/com/mindprod/common11/class-use/VersionCheck.html
com/mindprod/common11/javadoc/com/mindprod/common11/package-frame.html
com/mindprod/common11/javadoc/com/mindprod/common11/package-summary.html
com/mindprod/common11/javadoc/com/mindprod/common11/package-tree.html
com/mindprod/common11/javadoc/com/mindprod/common11/package-use.html
com/mindprod/common11/javadoc/constant-values.html
com/mindprod/common11/javadoc/deprecated-list.html
com/mindprod/common11/javadoc/help-doc.html
com/mindprod/common11/javadoc/index-all.html
com/mindprod/common11/javadoc/index.html
com/mindprod/common11/javadoc/overview-tree.html
com/mindprod/common11/javadoc/resources/inherit.gif
com/mindprod/common11/javadoc/serialized-form.html
com/mindprod/common11/javadoc/stylesheet.css
com/mindprod/common11/package-info.java
com/mindprod/common11/rebuild.xml
com/mindprod/common11/use.txt
com/mindprod/common11/version.txt

OK. What imports have you got in your source?
Avatar of alibax

ASKER

These are the imports:

import com.mindprod.filetimes.*;
import com.mindprod.common11.*;

The imports seems to work but some of the errors are still there:

mactime.java:16: cannot find symbol
symbol  : method getFileLastAccessed()
location: class java.io.File
                        long lastAccessed = filename.getFileLastAccessed();
                                                    ^
mactime.java:21: cannot find symbol
symbol  : method getFileCreated()
location: class java.io.File
                                long created = filename.getFileCreated();
                                                       ^
mactime.java:26: getFileLastModified(java.lang.String) in com.mindprod.filetimes
.FileTimes cannot be applied to ()
                                long lastModified = FileTimes.getFileLastModified();
                                                             ^
mactime.java:38: cannot find symbol
symbol  : method getFileLastAccessed()
location: class java.io.File
                                long lastAccessed = filename.getFileLastAccessed();
                                                            ^
mactime.java:43: cannot find symbol
symbol  : method getFileCreated()
location: class java.io.File
                                long created = filename.getFileCreated();
                                                       ^
mactime.java:48: getFileLastModified(java.lang.String) in com.mindprod.filetimes
.FileTimes cannot be applied to ()
    long lastModified = FileTimes.getFileLastModified();
                                                             ^
6 errors

why these  errors occur ? all the function used do exist in the file times class
Looks as if there could be something wrong with the download
Those methods you're calling with void parameters mostly take String as a param
Avatar of alibax

ASKER

Yes! in the filetimes class they do take String as parameter.....but with String it still produces the same error. I have read what the error[cannot find symbol] means in here: http://mindprod.com/jgloss/compileerrormessages.html#CANNOTFINDSYMBOL

At the same time it seems that the methods for times when called is referred in the location java.io.File, whereas it should have been in com.mindprod.filetimes  ??!!

Error:

C:\>javac mactime2.java
mactime2.java:17: cannot find symbol
symbol  : method getFileLastAccessed()
String lastAccessed = f.getFileLastAccessed();
                                               ^
mactime2.java:23: cannot find symbol
symbol  : class f
location: class mactime2
                                String created = f.super.getFileCreated();
                                                 ^
mactime2.java:28: not an enclosing class: com.mindprod.filetimes.FileTimes
String lastModified = FileTimes.super.getFileLastModified();
                                                               ^
mactime2.java:40: cannot find symbol
symbol  : class f
location: class mactime2
 String lastAccessed = f.super.getFileLastAccessed();
                                                      ^
mactime2.java:45: cannot find symbol
symbol  : method getFileCreated()
location: class java.io.File
                                String created = f.getFileCreated();
                                                  ^
mactime2.java:50: not an enclosing class: com.mindprod.filetimes.FileTimes
  String lastModified = FileTimes.super.FileLastModified();
                                                               ^
Note: mactime2.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
6 errors

import com.mindprod.filetimes.*;
import com.mindprod.common11.*;
 
import java.io.*;
import java.util.*;
 
public class mactime2{
	public static void main(String[] args) throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("Please Enter a File/Directory name: ");
		File f = new File(in.readLine());
		if (f.isDirectory()){
			if (f.exists()){
			
			long current = System.currentTimeMillis();
			
			String lastAccessed = f.getFileLastAccessed();
				
				
				System.out.println("File name : " + f.getName());
				System.out.println("File Last access date and time : " + new Date(lastAccessed));
				
				String created = f.super.getFileCreated();
				System.out.println("File name : " + f.getName());
				System.out.println("File creation date and time : " + new Date(created));
				
				
				String lastModified = FileTimes.super.getFileLastModified();
				System.out.println("File name : " + f.getName());
				System.out.println("File last modification date and time : " + new Date(lastModified));
			}
			else{
				System.out.println("Directory not found!");
				System.exit(0);
			}
		}
		else{
			if (f.exists()){
				long current = System.currentTimeMillis();
				String lastAccessed = f.super.getFileLastAccessed();
				
				System.out.println("File name : " + f.getName());
				System.out.println("File Last access date and time : " + new Date(lastAccessed));
				
				String created = f.getFileCreated();
				System.out.println("File name : " + f.getName());
				System.out.println("File creation date and time : " + new Date(created));
				
				
				String lastModified = FileTimes.super.FileLastModified();
				System.out.println("File name : " + f.getName());
				System.out.println("File last modification date and time : " + new Date(lastModified));
				
			}
			else{
				System.out.println("File not found!");
				System.exit(0);
			}
		}
	}
}

Open in new window

Avatar of alibax

ASKER

Sorry Correction there is no need for the use 'super' keyword..... is there?

Note: Location

C:\>javac mactime2.java
mactime2.java:17: cannot find symbol
symbol  : method getFileLastAccessed()
location: class java.io.File
String lastAccessed = f.getFileLastAccessed();
                                               ^
mactime2.java:23: cannot find symbol
symbol  : method getFileCreated()
location: class java.io.File
String created = f.getFileCreated();
                                                  ^
mactime2.java:28: getFileLastModified(java.lang.String) in com.mindprod.filetimes.FileTimes cannot be applied to ()String lastModified = FileTimes.getFileLastModified();
                                                               ^
mactime2.java:40: cannot find symbol
symbol  : method getFileLastAccessed()
location: class java.io.File
String lastAccessed = f.getFileLastAccessed();
                                                       ^
mactime2.java:45: cannot find symbol
symbol  : method getFileCreated()
location: class java.io.File
  String created = f.getFileCreated();
                                                  ^
mactime2.java:50: cannot find symbol
symbol  : method FileLastModified()
location: class java.io.File
String lastModified = f.FileLastModified();
                                                       ^
Note: mactime2.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
6 errors
>>String lastAccessed = f.getFileLastAccessed();

There is no such method in java.io.File, which is what you're calling it on...
Your question was titled "Date and Time stamp - in C programming  language". You already got solutions for that half a year ago. So what the heck is going on here?
This should get you started with the library
mactime2.java.txt
Avatar of alibax

ASKER

jkr  >>"You already got solutions for that half a year ago..."  No! there was no solution provided as you can see the problem continues.  The suggestion were provided and I did took at it further; the msdn2 url you have provide for C programming, I couldn't understand it and that resulted in Java, which Its a bit favourable than C.

I got runtime error: Does this mean I havent set the path properly ? if so what do I need to do with the jni files and classes...

Exception in thread "main" java.lang.UnsatisfiedLinkError: no nativefiletimes in java.library.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at com.mindprod.filetimes.FileTimes.<clinit>(FileTimes.java:326)
        at mactime3.main(mactime3.java:28)
Avatar of alibax

ASKER

Hi! Just an update. I have emailed the person developed the file times class and his response is:

"You need various aux files from com.mindprod.common11 and com.mindprod.filetimes. Put your class in a package. Bundle it with the common11 and filetimes classes in a jar, much like the one that came with filetimes. You also have to put the filetimes.dll on the path somewhere. "

 >> Bundle it with the common11 and filetimes classes in a jar, much like the one that came with filetimes.  what does this mean... is this referring to the imports?  
>> You also have to put the filetimes.dll on the path somewhere. ?? how is this set?

Sorry for trouble guys! I am still learning!! and you cant learn without asking!!

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Object. Again... Once more... Err, well, the last time, I promise. Maybe.
The solutions sugested only won't work if you let a [*meep*] have its way ("OK, let's try this C code with a Javac ompiler") . Then, I am inclined to say "let it be", though.
Is it really surprising that I'd like to object again for the same aforementioned reasons? They haven't really changed so far ;o)
No, let's give ignorance some room. I will take back my objections and promise to never try to help the asker again, even if needed, is this a deal?

I never thought that it would be so hard to... err, well... whatever...
I am fine with that as well. Yet I would never stand in anyone's way when it comes to be the gut feeling of really waning to be ignorant.
Let me add that I am fine with a plain "Delete" at the moment also - just let this *beep* Q get off my radar. A lot of time has already been wasted to p*ss experts off regarding the original asker, not you mods (even though *your* time was being wasted to a considreable extent as well).
Well i spent a considerable amount of time on this, even including downloading a third party API and making it work and answered the question as far as i'm concerned.
Avatar of alibax

ASKER

When providing a possible solution can you please varify that the solution work before posting for to the user. This will only result in delaying and response ....
Avatar of alibax

ASKER

What a heck is going on here???? No points were awarded because there was no solution for any of them. You want me to award points for no solutions? wtf.

But I do have to say if there is a person to be awarded for any of the points if not all of it is CEHJ. He has been supporting the question all the way through it, though there was no solution with the errors found. I have tried to follow the advice but nothing worked, and I also kept update with the question. I even tried to tempt the so called experts with more point by opening another question as a pointer but that didnt work either.

The reason why the entire question were deleted is because the was no solution. Correct me if I am wrong-  you award points based on the solution provided! right? NO SOLUTION, NO POINT AWARDED.

Having said that! and see people worked about the point, the only person deserved  a credit solely on the support provided is CEHJ.  This is the reason I will accept the CEHJ.

NOTE: NO ABSOLUTE SOLUTION PROVIDED
Thank you alibax, but i'm interested to know what you still need that you haven't got
>>NOTE: NO ABSOLUTE SOLUTION PROVIDED

I suggest you learn to understand what all others wrote. Your question was "Date and Time stamp - in C programming  language". Plenty of answers were given. If you are unable to understand or use them, that's a different thing.
Should be deleted altogether from what I can see, can't see anyone getting much value from reading thru it. Just another pile of waffle going into the PAQ db

Oh, and as far as non-admin issues are concerned: *PLONK*. Maybe the gus/gals in "Java" are more forgiving. You have my hearty FOAD for being simply plain ignorant. We do not need people like you on EE, IMHO. Whatever you credit card buys you, it is *NOT* *people* like me. Case closed. Unsubscribing...
yes if experts stopped entertaining these kinds of situations EE would be a better place.