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

网络营销渠道管理乐云seo官网

网络营销渠道管理,乐云seo官网,网络营销网站有哪些,门户网站信息流广告怎么做定义一个类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.15wanjia.com/news/172434.html

相关文章:

  • 怎么编写一个网站wordpress保存图片不显示
  • 北京企业建站哪家好h5可以制作公司网站吗
  • 兼职做问卷调查的网站湖南网站设计亮点
  • 高中信息技术网站设计规划卫浴品牌排行榜前十名
  • 长沙网站排名方法变更网站做推广需要备案
  • 在线设计logo的网站WordPress ajax查询
  • 做网站用jsp还是html网站设置右击不了如何查看源代码
  • 厦门企业网站制作大学网站建设多少钱
  • 武都区建设局网站网站建设完成后 下一步做什么
  • 江西城市建设管理协会网站互联网推广软件
  • 沧州网站建设代理价格兰州瞒报数据
  • 网站开发技术html5wordpress cdn缓存
  • a最先基智网站建设WordPress城市切换
  • 网站推广流程是网站设计书的结构
  • 网站备案号查不到angular wordpress
  • 网站设计规划范文河北省建设局网站首页
  • 各大网站域名食品公司
  • 五金网站模板江苏建设学院
  • 简单模板网站制作时间管理信息系统网站建设
  • wordpress做定制T恤的网站建设工程合同的内容有哪些
  • 行业网站 源码上海大型网站建设
  • wordpress做企业网站淘宝客单页网站怎么做
  • 临桂区建设局网站建立一个网站要什么条件
  • 住建局常宁seo外包
  • 影视网站策划书佛山网站优化排名推广
  • 展示型网站功能wordpress 前端发帖
  • 找摄影作品的网站做期货关注网站
  • 网站访问量来源沈阳自助建站软件
  • 外贸网站推广渠道北京科技公司名单
  • 客栈网站建设茶叶电子商务网站建设的结论