【问题标题】:How to get file IFile from file name in eclipse?如何从eclipse中的文件名获取文件IFile?
【发布时间】:2023-03-14 04:33:01
【问题描述】:

将文件名作为字符串。例如:Sample.c。 如何从中获取 IFile?

【问题讨论】:

  • 你需要知道它在哪个文件夹/项目中。你知道吗?
  • @greg-449 :不知道。获取文件路径为 C:\Users\runtime-EclipseApplication\Rule_Validate\Sample_Test.h 是否可以从 IFile 中获取此信息?

标签: eclipse eclipse-plugin eclipse-cdt


【解决方案1】:

如果您的路径是文件系统中的完整路径,您可以使用:

IPath path = new Path("C:\\Users\\runtime-EclipseApplication\\Rule_Validate\\Sample_Test.h");

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

IFile file = root.getFileForLocation(path);

注意:如果该位置不在工作区中,则结果可能是null

如果您有相对于工作空间的路径或工作空间中的项目/文件夹,还有其他 API。

【讨论】:

    猜你喜欢
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    • 2017-09-09
    • 1970-01-01
    相关资源
    最近更新 更多