文件操作

确认过眼神,遇见对的人


Tool one: MATLAB

function lower: lower(str)–将字母变成小写

function findstr: index = findstr(str1, str2)–从str1中寻找str2,并返回位置

function dir:
List = dir(pathstr)–列出当前目录下所有文件和子文件夹
List = dir(‘*.m’)–返回后缀为m的文件和子文件夹
dir的返回值是结构体,不排序:
struct

function exist: exist(var)–判断var是否存在,可以是变量、文件等等

function isdir/mkdir isdir(path)–判断路径是否是目录mkdir(path)–创建目录

读取文件中特定行

%% 读取特定行, 跳过499*1081行,读取1081*4数据
    fid = fopen(laserFile,'r');
    laser = cell2mat(textscan(fid,'%f %f %f %f',1081,'HeaderLines',500*1081));

Tool two: VS/C++

void getFiles(std::string path, std::vector<std::string>& files, std::vector<std::string>& catalogs)
{
    //文件句柄
    long hFile = 0;
    //文件信息
    struct _finddata_t fileinfo;
    std::string p;
    if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
    {
        do
        {
            //如果是目录,加入目录列表
            if ((fileinfo.attrib & _A_SUBDIR))
            {
                if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
                {
                    //getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
                    catalogs.push_back(p.assign(path).append("\\").append(fileinfo.name));
                }


            }
            else
            {
                files.push_back(p.assign(path).append("\\").append(fileinfo.name));
            }

        } while (_findnext(hFile, &fileinfo) == 0);
        _findclose(hFile);
    }
}

Tool three: Python

import os

 if os.path.exists(path):
     files = os.listdir(path)
 else:
     message = "sorry, can not find '%s' file."
     print(message % xml_path)
     return

 for file in files:
     #判断是否是正确的文件
     (file_name,extension) = os.path.splitext(file)
     if extension != '.xml':
     print(file + ' is not xml file.')
     continue

     print(file)

我的故事都是关于你

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值