It's all about the answers!

Ask a question

How to programmatically get Creation/LastModified file dates

ofir politansky (11) | asked May 24 '11, 8:12 a.m.
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

One answer

permanent link
Michael Valenta (3.7k3) | answered May 24 '11, 9:57 a.m.
We have a tool that does the same thing. Here's the code that does that part:

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(
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?
+ &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;

Your answer

Register or to post your answer.