如何使用Matlab搜索特定后缀名的文件,把该文件所在的文件夹路径提取出来?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用Matlab搜索特定后缀名的文件,把该文件所在的文件夹路径提取出来?相关的知识,希望对你有一定的参考价值。
使用Matlab搜索特定后缀名的文件,把该文件所在的文件夹路径提取出来方法如下:加入文件夹搜索路径 -- addpath (Add folders to search path)
ddpath('folderName1','folderName2','folderName3' ...)
addpath('folderName1','folderName2','folderName3' ... flag)
addpath folderName1 folderName2 folderName3 ... -flag)
previous_path = addpath(...)
这里的flag为
'-begin' :Add specified folders to the top of the search path.
'-end' :Add specified folders to the bottom of the search path.
'-frozen' :Disables change detection for folders you add to the path, which conserves Windows change notification resources (Windows only). Typehelp changenotification in the Command Window for more information.
例子:
Add c:/matlab/myfiles to the top of the search path:addpath('c:/matlab/myfiles')Add c:/matlab/myfiles to the end of the search path:addpath c:/matlab/myfiles -endAdd myfiles and its subfolders to the search path:addpath(genpath('c:/matlab/myfiles'))
On Windows, Add myfiles to the top of the search path, disable folder change notification, and display the search path before adding myfiles:previous = addpath('c:/matlab/myfiles', '-frozen')
去除文件夹搜索路径 rmpath (Remove folders from search path)
rmpath('folderName') removes the specified folder from the search path . Use the full path forfolderName.
rmpath folderName is the command form of the syntax.
如果想把该目录下的所有子目录都添加到路径中去,也不用把所有的子目录逐一addpath,用genpath函数:
Use genpath in conjunction with addpath to add a folder and its subfolders to the search path. Add myfiles and its subfolders to the search path:
addpath(genpath('c:/matlab/myfiles') 参考技术A 我自己专门写了这个函数,不仅找特定后缀名的,只要是文件名中特定字符串都行,遍历所选文件夹下面所有的文件和子文件夹,挺方便的,进一步可以实现对批量文件的删除、修改等等 参考技术B 使用dir函数本回答被提问者采纳
以上是关于如何使用Matlab搜索特定后缀名的文件,把该文件所在的文件夹路径提取出来?的主要内容,如果未能解决你的问题,请参考以下文章