how to check a path? file or folder?
11 次查看(过去 30 天)
显示 更早的评论
回答(3 个)
Stephen23
2015-2-12
编辑:Stephen23
2015-2-22
You can check for the existence of a specific file or a folder using exist . You can use the second argument to tell the function what kind of things you want to check for, and check that the output is the expected number:
2==exist('root\directory\filename.jpg','file')
S = dir('root\directory\*.jpg')
You can use relative or absolute paths, and the function returns a structure containing information that you might find useful, particularly the isdir logical.
0 个评论
Michael Haderlein
2015-2-12
Use the exist() function. It will return 2 for a file, 7 for a folder, and, in case the path does not exist at all, you'll get the value 0 and can do error handling.
1 个评论
Michael Haderlein
2015-2-12
...or, as Stephen has mentioned, use dir(). You'll need that to go through, anyway.
Image Analyst
2015-2-18
You say "If it is a folder, I would like to go through its content and use all jpg images in there." So see my demo which goes through the folder and all its subfolders getting image filenames. You can then display or process them - whatever you want.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!