Create virtual file from file path
Hi,
In my plugin, while performing some operations I delete a file from the project workspace.
I have the absolute path of the file.
I want to create a virtual file object from this path, I tried using the code below but
it returns a null virtual file object.
Any idea if I am missing something in this code?
final MockVirtualFile mockRepresentation = new MockVirtualFile();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
try {
VirtualFile vFile = mockRepresentation.createChildData(this.getClass(),fileName);
}
catch (IOException e) {
e.printStackTrace();
}
}
});
Please sign in to leave a comment.
Hello guest,
g> In my plugin, while performing some operations I delete a file from
g> the project workspace. I have the absolute path of the file.
g>
g> I want to create a virtual file object from this path, I tried using
g> the code below but it returns a null virtual file object.
The correct code for this task is:
LocalFileSystem.getInstance().findFileByPath(path);
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
LocalFileSystem.getInstance().findFileByPath(path);
api returns me 'null' because the file is deleted from the workspace.
What I need is a handle (it can be a new handle) to this file, so if the file is deleted is it possible to create a new VirtualFile object that just creates handle to file for the given path.
Hello guest,
g> LocalFileSystem.getInstance().findFileByPath(path); api returns me
g> 'null' because the file is deleted from the workspace.
g>
g> What I need is a handle (it can be a new handle) to this file, so if
g> the file is deleted is it possible to create a new VirtualFile object
g> that just creates handle to file for the given path.
Why do you need a VirtualFile pointing to a deleted file? Most operations
using that file will fail.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"
I'm not sure I understand 100% what you want, but if you need the handle to virtual file, that automaticaly tracks file deletion/creation, please look at VirtualFilePointer class, which instances are created with VirtualFilePointerManager.