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 |
One answer
![]()
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 & 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<StateId<IFileItem>, IFileItem> map = itemMap.get(teamRepository); if (map != null) { IFileItem fileItem = map.get(new StateId<IFileItem>(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() + " is shared but has no remote cached"); } } } 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> |
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.