windows资源管理器(只能看,不能用)
实现Windows资源管理器
##问题描述
Windows资源管理器是用来管理计算机资源的窗口,电脑里所有的文件都可以在资源管理器里找到,可以在资源管理器里查看文件夹的分层结构,可以利用资源管理器快速进行文件和文件夹的操作。例如,磁盘(根)、目录、不同类型的文件。 其中,文件信息包括文件名、类型、创建时间、文件大小等;磁盘信息包括磁盘名称、总大小、可用空间等;目录信息包括目录名称、修改日期、大小、对象数等。
基本要求
(1)构造一个空的资源管理器;
(2)新建/删除磁盘;
(3)在当前选择目录下新建/删除目录;
(4)在当前选择目录下新建/删除文件;
(5)以目录树的形式输出当前目录下的文件以及文件夹信息,并统计目录数和文件数;
(6)回上一级:当前目录为当前目录的上一级目录,并以目录树的形式输出当前目录下的文件以及文件夹信息,并统计目录数和文件数;
(7)模糊查找目录/文件信息,并显示查找结果;
(8)撤销一个资源管理器。
思路
链表烦死了,但是还只能用链表写(貌似其实正解是二叉树),书上东西还没有看完就开工了,最后实现了一个看起来有点像二叉树的树形结构,样式的话其实是模仿了命令行的设计,用一整行命令去实现操作,看起来比较美观,但是有些隐藏Bug可能还没发现,但是目前为止是能用的,写了400多行,腰酸背痛,要gg了,呜呜~
文件文件夹结构体实现
struct file {
int date_hour;
int date_min;
int date_sec;
string m_name;
string m_type="默认";
int m_zone;
file *nex;
file(string name, string type, int zone,file *Nex=NULL):m_name(name),m_type(type),m_zone(zone),nex(Nex){
time_t time_seconds = time(0);
localtime_s(&now_time, &time_seconds);
this->date_hour =now_time.tm_hour;
this->date_min = now_time.tm_min;
this->date_sec = now_time.tm_sec;
}
file *insertAfter(string name, string type, int zone) {
nex = new file(name, type, zone, nex);
return nex;
}
};
struct floder {
file *F_first;
int date_hour;
int date_min;
int date_sec;
int max_Size;
floder *nex;//同级
floder *link;//子文件夹
string m_name;
floder(){
F_first = new file(" ", " ", 100);
time_t time_seconds = time(0);
localtime_s(&now_time, &time_seconds);
this->date_hour = now_time.tm_hour;
this->date_min = now_time.tm_min;
this->date_sec = now_time.tm_sec;
nex = link = NULL;
}
floder(string name,int size,floder *Nex=NULL):m_name(name),max_Size(size),nex(Nex) {
F_first = new file(" "," ",100);
time_t time_seconds = time(0);
localtime_s(&now_time, &time_seconds);
this->date_hour = now_time.tm_hour;
this->date_min = now_time.tm_min;
this->date_sec = now_time.tm_sec;
//nex = NULL;
link = NULL;
}
floder *insrtAfter(string name,int size){
nex = new floder(name,size,nex);
return nex;
}
void insertLink(string name,int size) {
link = new floder(name, size, link);
}
};
命令行操作类实现
void print_Time(floder *p);
void print_Time(file *p);
class Disk {
floder user;
string name;
string path;
floder *cur_Disk;
public:
Disk(){
name = "@Titordong";
path=name+ "\\";
//user.nex = new floder();
}
floder*GetHead() { return &user;}
string GetPath() {
return path;
}
void PrintPath() {
cout << path << ">";
}
floder* Open_Floder(floder *cur, string aim) {
bool flag = false;
floder *temp = cur;
cur = cur->link->nex;
while (cur!= NULL) {
if (cur->m_name == aim) {
if (temp == &user) {
cur_Disk = cur;
}
flag = true;
path += cur->m_name;
path += "\\";
return cur;
}
else cur = cur->nex;
}
if (flag == false) {
cout << "无效路径!" << endl;
return temp;
}
return cur;
}
floder *quit(floder *cur) {
if (cur == &user) {
cout << "已到达根内存" << endl;
return cur;
}
floder *ans = NULL;
query_Dir(&user,cur,ans);
if (ans == NULL) {
cout << "失败!!!" << endl;
return cur;
}
path = path.substr(0, path.length() - 1);
while (path[path.size() - 1] != '\\') {
path = path.substr(0, path.length() - 1);
}
return ans;
}
bool query_Dir(floder *cur,floder *aim,floder*&ans) {
floder *p = cur->link,*temp=cur;
if (p != NULL)
p = p->nex;
while (p!=NULL) {
if (p == aim) {
ans = temp;
return true;
}
else {
if (query_Dir(p, aim, ans))return true;
p = p->nex;
}
}
return false;
}
int query_Zone(floder *p) {
long long ans = 0;
floder* t = p->link;
if(t!=NULL)
t=t->nex;
while (t != NULL) {
ans += query_Zone(t);
t = t->nex;
}
file *q = p->F_first->nex;
while (q != NULL) {
ans += q->m_zone;
q = q->nex;
}
return ans;
}
void find(string Path, floder *src, string aim) {
floder *p = src->link;
if (p != NULL) {
p = p->nex;
}
while (p != NULL) {
if (cmp(p->m_name, aim)) {
cout <<setw(10)<< Path << "> "<<setw(20)<< p->m_name <<setw(20)<<"<DIR>"<< endl;
}
if(Path[Path.size()-1]!='\\')
find(Path + "\\" + p->m_name, p, aim);
else find(Path + p->m_name, p, aim);
p = p->nex;
}
file *q = src->F_first->nex;
while (q != NULL) {
if (cmp(q->m_name, aim)) {
cout <<setw(10)<< Path << "> " <<setw(20)<< q->m_name << endl;
}
q = q->nex;
}
}
bool cmp(string a, string b) {
if (a.size() < b.size())return false;
for (int i(0); i < a.size(); i++) {
bool flag = true;
for (int j(0); j < b.size(); j++) {
if (a[i] != b[j])flag = false;
}
if (flag == true)return true;
}
return false;
}
void Display_Dir(floder*cur) {
if (cur == &user) {
cout << "请先进入一个磁盘" << endl;
return;
}
int num_F = 0, num_D = 0;
long long all_zone = query_Zone(cur);
floder *p = cur->link;
if(p!=NULL)
p = p->nex;
while (p != NULL) {
print_Time(p);
cout<<setw(20) << "<DIR>" << setw(29) << p->m_name << endl;
num_D++;
p = p->nex;
}
file *q = cur->F_first->nex;
while (q != NULL) {
print_Time(q);
cout<< setw(20) << q->m_type << setw(10) << q->m_zone << "字节" << setw(15) << q->m_name << endl;
num_F++;
q = q->nex;
}
cout << setw(40) << num_F << "个文件,已用" << all_zone << "个字节" << endl;
cout << setw(40) << num_D << "个目录,剩余可用空间" <<cur_Disk->max_Size-all_zone<<"字节"<< endl;
}
void Add_Disk(string name,int size=0) {
floder *p = GetHead()->link;
if (p == NULL) {
p = new floder("hh",0);
GetHead()->link = p;
}
while (p->nex!= NULL) {
p = p->nex;
}
p=p->insrtAfter(name,size);
}
void Add_floder(string name, floder *src) {
if (src == &user) {
cout << "请先创建磁盘!" << endl;
return;
}
floder *p = src->link,*temp=src;
if (p == NULL) {
p=new floder("hh", 0);
src->link = p;
}
while (p->nex != NULL) {
p = p->nex;
}
p=p->insrtAfter(name,0);
temp->date_hour = p->date_hour;
temp->date_min = p->date_min;
temp->date_sec = p->date_sec;
}
void Add_file(string name, string type, int size, floder *src) {
if (src == &user) {
cout << "请先创建磁盘!" << endl;
return;
}
if (size > cur_Disk->max_Size - query_Zone(src)) {
cout << "内存不足!!创建失败!" << endl;
return;
}
file *p = src->F_first;
floder *temp = src;
while (p->nex != NULL) {
p = p->nex;
}
p=p->insertAfter(name, type, size);
temp->date_hour = p->date_hour;
temp->date_min = p->date_min;
temp->date_sec = p->date_sec;
}
void Delet_Dir(floder *src) {
file*q = src->F_first->nex,*t;
while (q != NULL) {
t = q;
q = q->nex;
delete t;
}
floder *p = src->link,*tt;
if (p != NULL)
p = p->nex;
while (p != NULL) {
tt = p;
Delet_Dir(p);
p = p->nex;
delete tt;
}
}
void Delet_D(floder*src, string aim) {
floder *p = src->link;
bool flag = false;
while (p!=NULL&&p->nex!= NULL) {
if (p->nex->m_name == aim) {
flag = true;
break;
}
p = p->nex;
}
if (flag) {
Delet_Dir(p->nex);
if (p->nex->nex == NULL) {
delete p->nex;
p->nex = NULL;
}
else {
floder*t = p->nex;
p->nex = p->nex->nex;
delete t;
}
}
else {
cout << "没有这个文件夹" << endl;
}
}
void Delet_File(file *src) {
file *p = src->nex,*t=src;
if (p->nex == NULL) {
delete p;
p = NULL;
}
else {
t->nex = p->nex;
delete p;
p = NULL;
}
}
void Delet_F(floder*src, string aim) {
file *p = src->F_first;
bool flag = false;
while (p->nex!=NULL) {
if (p->nex->m_name == aim) {
flag = true;
break;
}
p = p->nex;
}
if (flag) {
Delet_File(p);
}
else {
cout << "没有这个文件" << endl;
}
}
};
void print_Time(floder *p) {
cout << p->date_hour<<":";
if (p->date_min < 10)
cout << 0;
cout << p->date_min << ":";
if (p->date_sec < 10)
cout << 0;
cout << p->date_sec;
}
void print_Time(file *p) {
cout << p->date_hour << ":";
if (p->date_min < 10)
cout << 0;
cout << p->date_min << ":";
if (p->date_sec < 10)
cout << 0;
cout << p->date_sec;
}
主函数
#include"head.h"
#include<iostream>
#include<cstring>
#include<strstream>
using namespace std;
int main() {
Disk S;
char cmd[100];
char op[10],dir[10],type[10],name[10];
int size;
floder*cur = S.GetHead();
S.PrintPath();
while (1) {
cin.getline(cmd,100);
istrstream strin(cmd, sizeof(cmd));
strin >> op;
if (strcmp(op, "mkdir")==0) {
strin >> dir >> size;
if(cur==S.GetHead())
S.Add_Disk(dir,size);
else {
S.Add_floder(dir, cur);
}
S.PrintPath();
}
else if (strcmp(op, "dir") == 0) {
S.Display_Dir(cur);
S.PrintPath();
}
else if (strcmp(op, "cd") == 0) {
strin >> dir;
if (strcmp(dir, "..")) {
cur = S.Open_Floder(cur, dir);
S.PrintPath();
}
else {
cur=S.quit(cur);
S.PrintPath();
}
}
else if (strcmp(op, "type") == 0) {
strin >> name >> type >> size;
S.Add_file(name, type, size, cur);
S.PrintPath();
}
else if (op[0] == '\0') {
S.PrintPath();
}
else if (strcmp(op, "del") == 0) {
strin >> name;
S.Delet_D(cur, name);
S.PrintPath();
}
else if (strcmp(op, "rm") == 0) {
strin >> name;
S.Delet_F(cur, name);
S.PrintPath();
}
else if (strcmp(op, "whereis") == 0) {
strin >> name;
S.find(S.GetPath(), cur, name);
S.PrintPath();
}
else if (strcmp(op, "exit") == 0) {
return 0;
}
else {
cout << "无效的参数" << endl;
S.PrintPath();
}
}
return 0;
}
后记
其实指针链表蛮好玩的,噗~
2018/11/29 23:21:51
windows资源管理器(只能看,不能用)的更多相关文章
- SVN has atopping svn已停止工作 or windows资源管理器无限重启
准备在空间时间用用linux,就在自己的win7系统上安装了属性系统,用easyBCD安装的,谁知安装好之后win7系统下的svn客户端不能使用了,点击报错“SVN已停止工作”,随后怀疑是linux引 ...
- 使用windows资源管理器的排序规则
对于windows资源管理器 abc_1_def是要排到abc_10_def前面的 而一般的排序规则, 都会吧_10_排到前面 所以为了使用习惯, 最好用资源管理器的排序规则, windows有个AP ...
- 为Windows资源管理器右键菜单添加菜单项
为Windows资源管理器右键菜单添加菜单项 在Windows下命令行用的比较多,经常在资源管理器里翻到某个目录,若想要在此目录下跑命令,只能是打开cmd.exe,然后一路cd才能到达此目录. 每次都 ...
- 出现“Windows资源管理器已停止工作”错误
出现"Windows资源管理器已停止工作"错误 什么是资源管理器呢,explorer.exe进程的作用就是让我们管理计算机中的资源! 今天开电脑的时候就一直提示windows资源管 ...
- 怎样在Windows资源管理器中添加右键菜单以及修改右键菜单顺序
有时,我们需要在Windows资源管理器的右键菜单中添加一些项,以方便使用某些功能或程序. 比如我的电脑上有一个免安装版的Notepad++,我想在所有文件的右键菜单中添加一项用Notepad++打开 ...
- SharePoint 2010 "客户端不支持使用windows资源管理器打开此列表" 解决方法
SharePoint 2010 在“库”--“库工具”,有一个“使用资源管理器打开”的按钮,点上去报“客户端不支持使用windows资源管理器打开此列表”.如图: 解决方案:在“开始”--“管理工具” ...
- sqlserver和Windows资源管理器争用内存
sqlserver和Windows资源管理器在设置成相同的优先级的情况下(普通),Windows资源管理器优先于sqlserver对内存的征用.开始是
- Windows资源管理器文件名排序
Windows资源管理器文件名排序 Windows资源管理器文件名排序 背景:自然排序 什么是自然排序? 怎样按自然排序的规则进行排序? 基于Python的解决方案 参考材料 这学期担任了本科生教学助 ...
- WPF实现Windows资源管理器(附源码)
今天我来写一篇关于利用WPF来实现Windows的资源管理器功能,当然只是局部实现这个功能,因为在很多时候我们需要来实现对本机资源的管理,当然我们可以使用OpenFileDialog dialog ...
随机推荐
- mysql中replace替换字符串更改方法
MySQL中update替换部分字符串replace的简单用法 近日,遇到了需要将部分字符串替换为另外的字符,平时用的最多的是直接update整个字段值,在这种情况下效率比较低,而且容易出错.其实my ...
- jQuery使用(十四):extend()方法
浅层克隆 深层克隆 扩展方法 一.extend的基本使用 语法: $.extend( target [, object1 ] [, objectN ] ) $.extend( [deep ], tar ...
- Web常见漏洞修复建议
一.SQL注入修复建议 1.过滤危险字符,例如:采用正则表达式匹配union.sleep.and.select.load_file等关键字,如果匹配到则终止运行. 2.使用预编译语句,使用PDO需要注 ...
- SQLserver 数据库高版本无法还原到低版本的数据解决方法
sql server 数据库的版本只支持从上往下兼容.即高版本可以兼容低版本 .低版本不能兼容低版本.通常我们在开发时会用比较高的版本.但是部署到客户那边可能他们的数据库版本会比较低. 我们可以通过导 ...
- java.util.zip.ZipException: invalid entry size
启动maven项目时报java.util.zip.ZipException: invalid entry size (expected 7612 but got 5955 bytes) 可能是mave ...
- Vue生命周期中mounted和created的区别
参考链接:https://blog.csdn.net/xdnloveme/article/details/78035065
- shiro-core包引用的版本问题
在做shiro学习时,遇到这样的问题: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ ...
- Java消息队列--ActiveMq 初体验
1.下载安装ActiveMQ ActiveMQ官网下载地址:http://activemq.apache.org/download.html ActiveMQ 提供了Windows 和Linux.Un ...
- 【原创】大叔经验分享(8)创建hive表时用内部表还是外部表
内部表和外部表最主要的一个差别就是删除表或者删除分区时,底层的文件是否自动删除,内部表会自动删除,外部表不会自动删除,所以基础数据表一定要用外部表,即使误删表或分区之后,还可以很容易的恢复回来. 虽然 ...
- RFB Net笔记
ECCV2018 论文:Receptive Field Block Net for Accurate and Fast Object Detection 论文链接:https://arxiv.org/ ...