我有点编程的初学者,我需要帮助编写一个脚本,该脚本接受多个作为文件夹的字符串的输入,在 cmd 中针对当前位置的现有文件夹搜索文件夹列表,它显示哪个存在,哪个不存在。在现有的文件中,它显示了里面有多少文件。
例如,我在桌面目录中(假设它包含a,bb,c),我输入a,b,aa,bb,它将根据当前目录中的所有文件夹名称搜索a,b,aa,bb,然后它输出a,bb,c存在,aa,b不存在。然后它显示a,bb,c中有多少文件。
我的时间不多,非常感谢任何即时帮助。
I would suggest Boost.Filesystem, which is a cross-platform libary abstracting filesystem operations such as querying for files properties, creating, copying and moving files. As a bonus, it is proposed for standardisation in a future version of the C++ ISO standard.
As a starting point, here is an example that will process every file in a given directory.
#include <boost/filesystem.hpp>
#include <iostream>
int main(int argc, char* argv[])
{
if(argc == 2)
{
boost::filesystem::path directory(argv[1]);
if (boost::filesystem::exists(directory) && boost::filesystem::is_directory(directory))
{
boost::filesystem::directory_iterator begin(directory);
boost::filesystem::directory_iterator end;
while(begin != end)
{
std::cout << *begin << " ";
++begin;
}
std::cout << "\n";
}
}
}
It show you that you can:
Other function you could be interested in:
boost::filesystem::current_path()
)有一些很棒的库可以让这个过程变得非常轻松和跨平台。
Qt 和 Boost 是最知名的。
以下是相关类的文档链接,这些类将为您执行此操作:
我更喜欢Qt,因为长期以来文档已经很统一了,我也很喜欢IDE。