Check if file exists (without having the full name)
조회 수: 7 (최근 30일)
이전 댓글 표시
Lets call the file i want to save file1. I am versioning the files.
file1_v1-0
file1_v1-1
Lets say i want to save file1_v1-1. I want Matlab to check if file1 is already existing in the folder i want to save it.
- If file1_v1-1 is already there -> skip
- If file1_v1-1 is there but in an older version. -> Delete old version and save new one.
- If file1_v1-1 is not there at all. -> save file1_v1-1
I have huge trouble with point 2. I tried to build something with "dir " and "stringfind". But that was not very satitisfying. Also tried to use "exist" but i need the full filename to work with that
Hope i made my problem clear. Thanks for your help.
댓글 수: 0
답변 (1개)
Stephen23
2019년 5월 2일
편집: Stephen23
2020년 1월 1일
You might like to download my FEX submission nextname:
For example, I created two files named file1_v1-0.txt and file1_v1-1.txt, then called nextname to get the next available filename:
>> name = nextname('file1_v1','-0','.txt')
name = file1_v1-2.txt
You could adapt the function to also check the files' timestamps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!