diff options
| author | Alexander Khosrowshahi <alexk@vector35.com> | 2025-07-03 13:53:40 -0400 |
|---|---|---|
| committer | Alexander Khosrowshahi <alexk@vector35.com> | 2025-07-03 13:53:40 -0400 |
| commit | 533b8e546a00537d6945f5329decab4b74a5bf09 (patch) | |
| tree | fc4ee45f61ded3eeaf746f8828b2cc0373dd31a9 /python/project.py | |
| parent | dd5009bd17bc0d814c06d3a6962929084878f350 (diff) | |
Add get_files_by_path_in_project and get_path_in_project to C++ and python APIs
Diffstat (limited to 'python/project.py')
| -rw-r--r-- | python/project.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/python/project.py b/python/project.py index 4357f276..c8f87d2f 100644 --- a/python/project.py +++ b/python/project.py @@ -190,6 +190,22 @@ class ProjectFile: """ return core.BNProjectFileExport(self._handle, str(dest)) + def get_path_on_disk(self) -> Optional[str]: + """ + Get this file's path on disk + + :return: The path on disk of the file or None + """ + return core.BNProjectFileGetPathOnDisk(self._handle) + + def get_path_in_project(self) -> Optional[str]: + """ + Get this file's path in its parent project + + :return: The path on disk of the file or None + """ + return core.BNProjectFileGetPathInProject(self._handle) + class ProjectFolder: """ @@ -650,6 +666,43 @@ class Project: file = ProjectFile(handle) return file + def get_file_by_path_on_disk(self, path: str) -> Optional[ProjectFile]: + """ + Retrieve a file in the project by its path on disk + + :param path: Path of the file on the disk + :return: File with the requested path or None + """ + handle = core.BNProjectGetFileByPathOnDisk(self._handle, path) + if handle is None: + return None + file = ProjectFile(handle) + return file + + def get_files_by_path_in_project(self, path: str) -> List[ProjectFile]: + """ + Retrieve a file(s) by path in the project + Note that files in a project can share names and paths within the project + but are uniquely identified by a disk path or id. + + :param path: Path of the file(s) in the project, separate from their path on disk. + :return: List of files with the requested path + """ + count = ctypes.c_size_t() + value = core.BNProjectGetFilesByPathInProject(self._handle, path, count) + if value is None: + raise ProjectException("Failed to get list of project files by path in project") + result = [] + try: + for i in range(count.value): + file_handle = core.BNNewProjectFileReference(value[i]) + if file_handle is None: + raise ProjectException("core.BNNewProjectFileReference returned None") + result.append(ProjectFile(file_handle)) + return result + finally: + core.BNFreeProjectFileList(value, count.value) + def delete_file(self, file: ProjectFile) -> bool: """ Delete a file from the project |
