1

What I'm trying to achieve is to run a program, which thinks a folder exists within its own folder while actually the folder is somewhere else on the system.

So my program would launch a process and say to the process: Folder A which is at C:\A is within your own directory at C:\Program Files (x86)\SomeProgram\A

So the "virtual" directory would only be visible to that process.

I'm using Qt to program my program, so if there are any Qt functions I could use that would be great (in relation to portability). However, plan C++ or any windows-bound API's would be fine.

I was thinking about NTFS junctions or symbolic links but I would have no idea how to create either of those in C++, let alone bind them to a specific process.

Thanks in advance!

EDIT:

In relation to the above, I've found this question: https://superuser.com/questions/234422/does-windows7-support-symbolic-links-folder-shortcuts. However, it only shows how to perform the required actions from the command-line and it wouldn't be process bound.

EDIT 2:

Some extra information: I'm trying to create a virtual directory that is made up of a couple of other directories but then merged (I'm using a priority system to decide which files "win" from other files). These merged directories would then appear to the target process as one directory containing the merged files.

4

2 回答 2

0

这些任务是通过使用文件系统过滤驱动程序来完成的。该驱动程序截获操作系统对文件系统的请求,并允许您将自己的虚拟文件和目录插入到磁盘上的现有目录中。不过,过滤器驱动程序对于您的特定任务来说可能是一种过度杀伤力。

评论中提到的 Detours 方法需要在系统范围内挂钩文件 API,并且会减慢整个系统的速度(文件系统过滤器驱动程序连接到一个磁盘,这是一种记录在案的方法,因此它更快、更健壮)。

于 2014-10-26T08:00:24.900 回答
0

我想我会坚持使用 Window 的 mklink 命令。它似乎最适合我的需求。

我要做的是在非 Windows 的所有操作系统上使用 QFile::link(),在 Windows 上使用带有 mklink 的 QProcess。这应该适用于每个操作系统。

一个很好的例子看这里:https ://stackoverflow.com/a/21013935/979732

于 2014-09-29T08:03:59.173 回答