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;

 

转载于:https://www.cnblogs.com/yuguangyuan/p/6755782.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值