Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to programmatically get Creation/LastModified file dates

Hi
We need to go over all files in our project, and add a COPYRIGHT header.
We must have both "creation" and "last modified" years in this COPYRIGHT header.

How can we get those dates programmatically?
We guess there's some method in RTC SDK does anyone have some example to share?
Thank you

0 votes



One answer

Permanent link
We have a tool that does the same thing. Here's the code that does that part:

<pre>
public int getLastModifiedYear(IFile file, IProgressMonitor monitor)
throws CoreException {
IShareable shareable = Adapters.getAdapter(file, IShareable.class);
SubMonitor progress = SubMonitor.convert(monitor, 110);
try {
if (!shareable.shouldBeIgnored(progress.newChild(10))) {
int state = shareable.getState(progress.newChild(50));
int mask = IShareable.SHARED | IShareable.REMOTE;
if ((state &amp; mask) == mask) {
IShare share = shareable.getShare(progress.newChild(25));
ITeamRepository teamRepository = TeamPlatform.getTeamRepositoryService().getTeamRepository(
share.getSharingDescriptor().getRepositoryUri());
IVersionableHandle remote = shareable.getRemote(progress.newChild(25));
if (remote != null) {
Map&lt;StateId&lt;IFileItem&gt;, IFileItem&gt; map = itemMap.get(teamRepository);
if (map != null) {
IFileItem fileItem = map.get(new StateId&lt;IFileItem&gt;(remote));
if (fileItem != null) {
return fileItem.getFileTimestamp().getYear() + 1900;
}
}
// Return a 0 to indicate that this file has not changed since the desired snapshot
return 0;
}
// How can something be shared without a remote?
System.out.println(file.getFullPath()
+ &quot; is shared but has no remote cached&quot;);
}
}
} catch (FileSystemException e) {
throw new CoreException(FileSystemStatusUtil.getStatusFor(e));
}
// By default, return a -1 so the current year will be used in the copyright
return -1;
}
</pre>

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,952

Question asked: May 24 '11, 8:12 a.m.

Question was seen: 4,986 times

Last updated: May 24 '11, 8:12 a.m.

Confirmation Cancel Confirm