TPath

本文详细介绍了使用IOUtils.TPath进行路径相关操作的常用方法,包括获取临时文件夹路径、临时文件名、盘符、路径、文件名、扩展名等,并提供了不常用的方法和属性介绍。

以后路径相关的处理, 用 IOUtils.TPath 就很方便了.
//较常用的方法:
TPath.GetTempPath;                   {获取临时文件夹路径}
TPath.GetTempFileName;               {获取一个临时文件名}
TPath.GetPathRoot();                 {提取盘符, 如: c:\}
TPath.GetDirectoryName();            {提取路径}
TPath.GetFileName();                 {提取文件名}
TPath.GetExtension();                {提取扩展名}
TPath.GetFileNameWithoutExtension(); {提取无扩展名的文件名}
TPath.ChangeExtension();             {更换扩展名}
TPath.DriveExists();                 {检查路径中的驱动器是否存在}
TPath.GetFullPath();                 {根据相对路径给出全路径}
TPath.HasExtension();                {判断是否有扩展名}
TPath.IsPathRooted();                {判断是否是绝对路径}
TPath.Combine();                     {结合路径}
TPath.GetRandomFileName;             {产生一个随机文件名}
TPath.GetGUIDFileName();             {用于产生一个唯一的文件名, 布尔参数决定名称中是否包含 -}
TPath.IsValidPathChar();             {判断给定的字符是否能用于路径名}
TPath.IsValidFileNameChar();         {判断给定的字符是否能用于文件名}

//不常用的方法
TPath.HasValidPathChars();
TPath.HasValidFileNameChars();
TPath.GetExtendedPrefix();
TPath.IsExtendedPrefixed();
TPath.IsUNCRooted();
TPath.IsDriveRooted();
TPath.IsUNCPath();
TPath.MatchesPattern();
TPath.GetInvalidFileNameChars;
TPath.GetInvalidPathChars;
TPath.GetAttributes();
TPath.SetAttributes();

//属性, 获取在不同平台下的各种路径分隔符, 都是只读的.
TPath.AltDirectorySeparatorChar;     {Windows 下是 "\"}
TPath.AltDirectorySeparatorChar;     {Windows 下是 "/"}
TPath.ExtensionSeparatorChar;        {Windows 下是 "."}
TPath.PathSeparator;                 {Windows 下是 ";"}
TPath.VolumeSeparatorChar;           {Windows 下是 ":"}

 

转载于:https://www.cnblogs.com/hnxxcxg/archive/2013/03/03/2941335.html

function [time,jw] = DataRead(mainPath,sensor,ts,te,pt) % pt : 采样周期; % if ~isdatetime(ts) try t1 = datetime(ts); catch error('SensorPath:开始时间必须为长度为6的向量,或datetime格式,或时间字符串格式!'); end else t1 = ts; end if ~isdatetime(te) try t2 = datetime(te); catch error('SensorPath:结束时间必须为长度为6的向量,或datetime格式,或时间字符串格式!'); end else t2 = te; end t1.Hour = 0; t1.Minute = 0; t1.Second = 0; t2 = t2-seconds(1); t2.Hour = 0; t2.Minute = 0; t2.Second = 0; time = (datetime(t1):seconds(pt):datetime(t2)-seconds(pt))'; %存在问题 fPath = SensorPath(mainPath,sensor,ts,te); tTokens1 = regexp(fPath,'.*\\(\d{4})\\(\d{2})\\(\d{2})\\.*(\d{2})(\d{2})(\d{2})_\d{2}\d{2}\d{2}\.\w*','tokens'); tTokens1 = [tTokens1{:}]'; tTokens2 = regexp(fPath,'.*\\(\d{4})\\(\d{2})\\(\d{2})\\.*\d{2}\d{2}\d{2}_(\d{2})(\d{2})(\d{2})\.\w*','tokens'); tTokens2 = [tTokens2{:}]'; if isempty(tTokens1) jw = nan(length(time),1); return end tstr1 = cellfun(@cell2mat,tTokens1,'UniformOutput',false); tPath1 = datetime(tstr1,'inputformat','yyyyMMddHHmmss'); tstr2 = cellfun(@cell2mat,tTokens2,'UniformOutput',false); tPath2 = datetime(tstr2,'inputformat','yyyyMMddHHmmss'); lenf = size(fPath,1); jwR = []; timeR = []; for i = 1:lenf tPath1i = tPath1(i); tPath2i = tPath2(i); if tPath2i.Minute == 0 && tPath2i.Hour == 0 && tPath2i.Second == 0 tPath2i.Hour = 24; end dti = tPath2i-tPath1i; try jwi = binReader(fPath{i});%读取 catch continue end % if dti == hours(0) % timei = (tPath1i:seconds(pt):tPath2i+days(1)-seconds(pt))'; % leni = length(timei); % if length(jwi)<leni % jwi = [jwi;nan(leni-length(jwi),1)]; % else % jwi = jwi(1:leni); % end % else timei = (tPath1i:seconds(pt):tPath2i-seconds(pt))'; leni = length(timei); if length(jwi)<length(timei) jwi = [jwi;nan(leni-length(jwi),1)]; else jwi = jwi(1:leni); end % end jwR = [jwR;jwi]; timeR = [timeR;timei]; end % [~,indsort] = sort(ind); [~,indsort] = sort(timeR); time = timeR(indsort); jw = jwR(indsort); % jwM = nan(12,lh); % jwM(:,tErr) = jwCell(:,indsort); % jw = reshape(jwM,[12*lh,1]); end
最新发布
09-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值