zoukankan      html  css  js  c++  java
  • Poco::Path 和 DirectoryIterator


    #include<iostream>
    #include<typeinfo>
    #include<Poco/Path.h>
    using namespace std;
    using namespace Poco;
    int main(){
        Path my_path ("/media/ygy/KINGSTON");
        Path path1 = my_path.absolute();
        cout<< Path::current()<<endl;
        cout <<my_path.depth()<<endl;

        for(int i=0;i<=path1.depth();i++){
            cout<<my_path.directory(i)<<endl;
            cout<<my_path[i]<<endl;
        }
    }

    root@goodjob:~/work/poco/path# ./test
    root@goodjob:~/work/poco/path# ./test
    /home/ygy/work/poco/path/
    2
    media
    media
    ygy
    ygy
    KINGSTON
    KINGSTON

    static std::string current();   Returns the current working directory.

    int depth() const;       Returns the number of directories in the directory list.

    const std::string & directory(int n) const; Returns the n'th directory in the directory list. If n == depth(), returns the filename.

    bool isDirectory() const;Returns true if and only if the path references a directory (the filename part is empty).

          只有路径字符串末尾是/的时候,判断为真,其余都是假。

    bool isFile() const; Returns true if and only if the path references a file (the filename part is not empty).

          路径字符串末尾不是/的时候,为真。

    Path & makeDirectory();

        If the path contains a filename, the filename is appended to the directory list and cleared. Thus the resulting path       always refers to a directory.

    Path & makeFile();

      If the path contains no filename, the last directory becomes the filename.

    Path & makeParent();

      Makes the path refer to its parent.

    Path parent() const;

        Returns a path referring to the path's directory.

    std::string toString() const;

       Returns a string containing the path in native format.

    #include<iostream>
    #include<typeinfo>
    #include<Poco/Path.h>
    #include <Poco/DirectoryIterator.h>
    using namespace std;
    using namespace Poco;
    
    int main(){
        Path my_path ("/media/ygy/YGY");
        cout<< Path::current()<<endl;
        DirectoryIterator end;
        DirectoryIterator it(my_path);
    cout<<"-------"<<endl;
        Path path2;
        for(;it!=end;++it){
        cout<<it.name()<<endl;
    //      path2 = it.path();  
    //      cout<<path2.getFileName()<<endl;
        }
    }

    root@goodjob:~/work/poco/path# ./test
    /home/ygy/work/poco/path/
    -------
    desaydata
    $TXRAJNL.DAT
    text
    libTextData.so
    update.zip
    update.zip.md5
    music
    DS03H_Common.kzb
    bin
    lib
    radio
    libsvp_appfw.so
    lns-pic
    global-menu
    picture
    1
    System Volume Information
    svp.test.mediafw.plugin.native
    动态规划
    2叉树
    排序
    libControls.so
    3.1.3
    3.1.10.2
    libPictureData.so
    svp.svc.appmgr
    svp.svc.media.indexing
    new folder
    libsvp_mediafw-plugin-native-db.so
    lns-pic-0
    lns-pic-1
    lns-pic-2
    genivi

    DirectoryIterator();

      Creates the end iterator.

    DirectoryIterator( const std::string & path);

      Creates a directory iterator for the given path.

    const Path & path() const;

      Returns the current path.

    const std::string & name() const;

      Returns the current filename.

    const File & operator * () const;

    const File * operator-> () const;

        cout<<(*it).canRead()<<endl;
        cout<<  it->canRead()<<endl;

     

  • 相关阅读:
    Lua笔记4 语句
    Corps humain
    La Famille
    短语
    Lua笔记6 编译、执行与错误
    poser une question
    Photon——Exception Handling 异常处理
    Photon——Calling Operations 调用操作
    Photon——Licenses 许可证
    Photon——Firewall Settings 防火墙设置
  • 原文地址:https://www.cnblogs.com/yuguangyuan/p/6755782.html
Copyright © 2011-2022 走看看