当前位置: 首页 > news >正文

通用网站建设更厉害的病毒2024

通用网站建设,更厉害的病毒2024,网站建设的视频教程,呼和浩特网站设计公司定义一个类CheckPath,它由两个public方法组成: 1) checkPath:检查传入的字符串指定的路径是否存在,存在返回true,否则返回false。 2) createFilePath:根据传入的字符串指定的路径&…

定义一个类CheckPath,它由两个public方法组成:

1) checkPath:检查传入的字符串指定的路径是否存在,存在返回true,否则返回false。

2) createFilePath:根据传入的字符串指定的路径,创建由 pathDepth指定的路径,例如:如果传入字符串为/home/user/aa/bb,如果指定的pathDepath为0,则不创建这个路径,如果pathDepath为1,则创建从/开始创建所有路径,如果pathDepath为2,则创建从/home开始创建所有路径。

class CheckPath{
public:bool checkPath(std::string &filePath);bool createFilePath(const char * path, int pathDepth);
};

checkpath.cpp源文件: 

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <iostream>
#include <sstream>
#include <fstream>#define MAX_FILENAME_LEN        256class CheckPath{
public:bool checkPath(std::string &filePath);bool createFilePath(const char * path, int pathDepth);
};/* 测试指定目录是否存在 */
bool CheckPath::checkPath(std::string &filePath)
{char lastChar;struct stat buff;int istat;int isDir = 0;bool pathExists = false;int len = filePath.size();if (len == 0) return false;lastChar = filePath[len - 1];if (lastChar == '/'){filePath.resize(len - 1);}istat = stat(filePath.c_str(), &buff);if (!istat) isDir = (S_IFDIR & buff.st_mode);if (!istat && isDir){pathExists = true;}filePath.append("/");return pathExists;
}/* 安pathDepath指定深度开始创建指定的目录 */
bool CheckPath::createFilePath(const char * path, int pathDepth)
{bool    result = true;char    * parts[MAX_FILENAME_LEN];int     num_parts;char    directory[MAX_FILENAME_LEN];char    nextDir[MAX_FILENAME_LEN];char    * saveptr;int     i = 0;/* donot create path */if (pathDepth == 0) return result;while ((path[i] == '/') && i < MAX_FILENAME_LEN){nextDir[i] = path[i];i++;}nextDir[i] = 0;printf("nextDir: %s\n", nextDir);strcpy(directory, &path[i]);printf("Directory: %s\n", directory);num_parts = 0;parts[num_parts] = strtok_r(directory, "\\/", &saveptr);while (parts[num_parts] != NULL){parts[++num_parts] = strtok_r(NULL, "\\/", &saveptr);}//        for (i = 0; i < num_parts; i++){
//                printf("%d: %s\n", i+1, parts[i]);//}if (pathDepth < 0){pathDepth = num_parts + pathDepth;if (pathDepth < 1) pathDepth = 1;}for (i = 0; i < num_parts && result != false; i++){strcat(nextDir, parts[i]);if (i >= pathDepth){//                printf("depath = %d,create path %s\n",i, nextDir);if (mkdir(nextDir, 0777) != 0 && errno != EEXIST){result = false;}}strcat(nextDir, "/");}return result;
}/* 测试主程序 */
int main(int argc, char ** argv)
{if (argc != 2){fprintf(stderr, "Usage: %s pathname\n", argv[0]);return -1;}std::string filePath = argv[1];std::cout << "Check File Path : " << filePath << " exists?" << std::endl;;CheckPath * pcp = new CheckPath();/* Test file path exists or not */std::cout << "*****************************************"<<std::endl;std::cout << "Test Function 1 checkPath:" << std::endl;if (pcp->checkPath(filePath)){std::cout << "FilePath:" << filePath <<" does exist" << std::endl;}else{std::cout << "FilePath:" << filePath << " does not exist" << std::endl;}std::cout << "*****************************************"<<std::endl<<std::endl;;std::cout << "*****************************************"<<std::endl;std::cout << "Test Function 2 createFilePath:" << std::endl;std::cout << "Please enter a path to create:";std::cin >> filePath;std::cout << "The path to create :" << filePath << std::endl;int depth;std::cout << "Please enter the create depth:";std::cin >> depth;printf("Depth: %d\n", depth);if (pcp->createFilePath(filePath.c_str(), depth)){std::cout << "Create the "  << depth << " depth of file path " << filePath << std::endl;}else{std::cout << "can not create file path " << filePath << std::endl;}std::cout << "*****************************************"<<std::endl;delete pcp;return 0;
}

编译以上代码,观察结果:

orangepi@orangepi5:~/C_program$ ./checkpath aa
Check File Path : aa exists?
*****************************************
Test Function 1 checkPath:
FilePath:aa/ does exist
**********************************************************************************
Test Function 2 createFilePath:
Please enter a path to create:/home/orangepi/C_program/aa/bb
The path to create :/home/orangepi/C_program/aa/bb
Please enter the create depth:3
Depth: 3
nextDir: /
Directory: home/orangepi/C_program/aa/bb
Create the 3 depth of file path /home/orangepi/C_program/aa/bb
*****************************************
orangepi@orangepi5:~/C_program$ ls aa/
bb

检查当前目录下aa目录时存在的,并且在aa目录下创建了一个bb目录。

http://www.hkea.cn/news/907334/

相关文章:

  • 网站免费建站k网络营销策划方案书
  • 网站建设类公网店推广的作用
  • 安平做网站除了百度指数还有哪些指数
  • 做网站公司 蓝纤科技知乎怎么申请关键词推广
  • 临沂免费做网站发表文章的平台有哪些
  • 网站推广的方式包括哪些广西网站建设制作
  • 杭州营销网站建设东莞网站建设哪家公司好
  • 企业做营销型网站手机如何制作网页
  • 连云港网站关键词优化seo自学教程
  • 网站全站出售淘宝关键词排名怎么查询
  • 龙口市规划建设局网站查询收录
  • 学校网站建设注意什么东莞网站营销推广
  • 网站设计模板是什么百度网盘人工客服电话多少
  • wordpress文章收缩长春seo优化企业网络跃升
  • 网站地图调用希爱力双效片骗局
  • 珠海网站建设维护友情链接买卖代理
  • 武汉企业网站推广外包网络广告营销案例分析
  • 深圳哪里有做网站的汕头seo排名收费
  • 如何用腾讯云主机做网站株洲发布最新通告
  • 中国建设银行官网站下载信息流广告投放公司
  • 合肥建站平台网络平台推广是干什么
  • 黄冈工程建设标准造价信息网优化工作流程
  • 怎么做服装外贸网站怎么去推广一个产品
  • 和各大网站做视频的工作总结软件推广赚佣金渠道
  • asp.net是做网站的吗企业文化培训
  • 有链接的网站怎么做seochan是什么意思
  • 开发公司 工程管理中存在问题seo人工智能
  • 网站卖给别人后做违法信息seo和点击付费的区别
  • 网站配色 绿色网络推广主要做什么
  • 个人网站制作多少钱公关公司的主要业务