#2
吹水佬2023-04-24 14:36
|
如果目录中,同时有.sln文件和.VS子目录,就删除.VS子目录
只有本站会员才能查看附件,请 登录
程序代码:
#include<iostream>
using namespace System;
using namespace System::IO;
using namespace System::Collections::Generic;
bool Seek_Harddisk_Partition(List<String^>^ list) //查找硬盘有几个分区
{
char diskpart[4] = { 'C',':','\\','\0' };
String^ _disk = gcnew String(diskpart);
if(!Directory::Exists(_disk))
return false;
while (Directory::Exists(_disk))
{
list->Add(_disk);
diskpart[0] += 1;
_disk = gcnew String(diskpart);
}
return true;
}
int CharOccurrenceNumber(String^ Str, String^ Ch) //查找路径中‘\’出现次数,来判断当前是第几层目录
{
int Ret = 0;
while(Str->IndexOf(Ch) != -1)
{
Ret++;
Str = Str->Substring(Str->IndexOf(Ch) + 1);
}
return Ret;
}
void Seek_Directory(String^ _path)
{
if (Directory::GetFiles(_path, "*.sln") != nullptr) //如果目录中,同时有.sln文件和.VS子目录,就删除.VS子目录
{
if (Directory::Exists(_path + "\.VS"))
Directory::Delete(_path + "\.VS");
}
if (CharOccurrenceNumber(_path, "\\") < 5) //寻找5层目录,
{
array<String^>^ PathList = Directory::GetDirectories(_path);
for each (auto i in PathList)
Seek_Directory(i);
}
}
int main()
{
List<String^>^ DiskList = gcnew List<String^>();
if (!Seek_Harddisk_Partition(DiskList))
return -1;
for each (auto i in DiskList)
Seek_Directory(i);
return 1;
}
using namespace System;
using namespace System::IO;
using namespace System::Collections::Generic;
bool Seek_Harddisk_Partition(List<String^>^ list) //查找硬盘有几个分区
{
char diskpart[4] = { 'C',':','\\','\0' };
String^ _disk = gcnew String(diskpart);
if(!Directory::Exists(_disk))
return false;
while (Directory::Exists(_disk))
{
list->Add(_disk);
diskpart[0] += 1;
_disk = gcnew String(diskpart);
}
return true;
}
int CharOccurrenceNumber(String^ Str, String^ Ch) //查找路径中‘\’出现次数,来判断当前是第几层目录
{
int Ret = 0;
while(Str->IndexOf(Ch) != -1)
{
Ret++;
Str = Str->Substring(Str->IndexOf(Ch) + 1);
}
return Ret;
}
void Seek_Directory(String^ _path)
{
if (Directory::GetFiles(_path, "*.sln") != nullptr) //如果目录中,同时有.sln文件和.VS子目录,就删除.VS子目录
{
if (Directory::Exists(_path + "\.VS"))
Directory::Delete(_path + "\.VS");
}
if (CharOccurrenceNumber(_path, "\\") < 5) //寻找5层目录,
{
array<String^>^ PathList = Directory::GetDirectories(_path);
for each (auto i in PathList)
Seek_Directory(i);
}
}
int main()
{
List<String^>^ DiskList = gcnew List<String^>();
if (!Seek_Harddisk_Partition(DiskList))
return -1;
for each (auto i in DiskList)
Seek_Directory(i);
return 1;
}
[此贴子已经被作者于2023-4-24 14:49编辑过]