finding path and timestamp of file used

조회 수: 1 (최근 30일)
Neesha
Neesha 2014년 12월 12일
댓글: Adam 2014년 12월 12일
Hi All,
I am reading data into dataset with rawData = dataset('XLSFile','myData.csv', 'sheet','myData');
I want to collect entire file path with timestamp so that i can later print it as report for all input files like this.
How do i do it?
  댓글 수: 1
Neesha
Neesha 2014년 12월 12일
I am using following to get the path now, just figured.
a = (fileparts(which('myData.csv')));
b = [a, '\', 'myData.csv'];
rawData = dataset('XLSFile','myData.csv', 'sheet','myData');
That gets me the path of the file and I make sure my file being read from that path. But how do i get time stamp?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2014년 12월 12일
Try this:
filename = which(mfilename('fullpath')) % Whatever you need.
fileInfo = dir(filename)
fprintf('The date of %s\nis %s\n', filename, fileInfo.date);
In the command window:
filename =
C:\Users\Neesha\Documents\MATLAB\work\Tests\test1.m
fileInfo =
name: 'test1.m'
date: '12-Dec-2014 15:01:02'
bytes: 395
isdir: 0
datenum: 735945.625717593
The date of C:\Users\Neesha\Documents\MATLAB\work\Tests\test1.m
is 12-Dec-2014 15:01:02
there is also the datenum value you can use if you need a number instead of a string.

추가 답변 (1개)

Adam
Adam 2014년 12월 12일
myFile = java.io.File( filename );
myFile.lastModified
myFile.getCanonicalPath
  댓글 수: 5
Neesha
Neesha 2014년 12월 12일
Yes it does give me timestamp if i use it with Dir and then .date.
Weird that it does not with myFile.LastModified
Adam
Adam 2014년 12월 12일
It doesn't give a struct. Those are actually functions not properties/fields. It confused me at first but
methods( myFile )
shows you the options.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by