【发布时间】:2017-07-24 10:41:06
【问题描述】:
#include <bits/stdc++.h>
using namespace std;
int main(int count, char* argv[])
{
if(count!=2)
{
// print_syntax(argv[0]);
}
else if(count==2)
{
string file_name=argv[1];
// cout<<file_name<<endl;
string file_directory="~/.local/share/Trash/info/"+file_name+".trashinfo";
cout<<file_directory<<endl;
ifstream myReadFile;
myReadFile.open(file_directory);
char output[100];
if (myReadFile.is_open())
{
cout<<"here";
while (!myReadFile.eof())
{
myReadFile >> output;
cout<<output;
}
}
else
{
cout<<"Not working";
}
myReadFile.close();
}
}
我正在尝试从垃圾箱中读取一个文件,该文件还有两个子文件夹,其中一个包含已删除文件的元数据,扩展名为 .trashinfo
但由于某种原因,我无法在此程序中打开该文件。
root@kali:~/projects/Linux-Commands/Restore# ./a.out hero
~/.local/share/Trash/info/hero.trashinfo
Not working
root@kali:~/projects/Linux-Commands/Restore# vi ~/.local/share/Trash/info/hero.trashinfo
通过使用这个 vi 命令,我可以很容易地在终端中打开它,甚至可以编辑它。
【问题讨论】:
-
'~' 由 shell 扩展,如果您从 C++ 程序执行此操作,则它不起作用。请查看stackoverflow.com/questions/2910377/…
-
~ 在这种情况下不能用于引用用户的私人目录。
-
确实,我今天学到了一些新东西。谢谢。
标签: c++ linux file-handling recycle-bin