How to locate files in folder or directory where I'm working?

조회 수: 3 (최근 30일)
Mario Martos
Mario Martos 2016년 5월 24일
댓글: Mario Martos 2016년 5월 25일
Hello,
I wanted to ask to see if someone could help on how I could locate files in the directory or folder where I'm working and making a logic for example if the file does not exist execute a function or process, and if it does not run.
That is, I have a function that creates an output named JS:
JSFile = strcat (partitura_xml, '_', youtube_id, '_', hashname);
For example, if I look in the folder and locate a file with the name:
Kyrie_eleison_Mozart_Requiem_Piano.xml_c0pmtmfry4U_09b5b682ceac451132efb529839115a8.js
It would not be necessary to run the process because it already exists and is identified; and instead if I do not; would have to execute the function that creates the JS me. I hope I explained well, is like making a logical process (if there is such js not process, if there is no process or call the corresponding function) and do not know how to implement or locate or find files in the folder ...
On the other hand, I wanted to ask whether take long to make that search, for example if I have 100 files or more this search would take me a lot, because in that case would have to make a database. Thanks in advanced!

답변 (2개)

Image Analyst
Image Analyst 2016년 5월 24일
Have you tried using dir(someFilePattern) and exist(filename, 'file')?
  댓글 수: 2
Mario Martos
Mario Martos 2016년 5월 25일
How? I do not understand what you mean to me ... What I want is: Imagine you have files in the folder or directory where I am working for example : Kyrie_eleison_Mozart_Requiem_Piano.xml_c0pmtmfry4U_09b5b682ceac451132efb529839115a8 and Fur_Elise_Beethoven.xml_NurQf2QOdvA_4d15879a283b76cdd2ed959e8e473b43.js ( For example , there may be many more) :
And I want to implement the control logic function , ie :
Whether or locate that have already js file (for example : one of the two before, not after running the process and return me example 1).
However if I do not have that file would have to execute the function or process to have it. I hope I explained more or less ... How could implement that with if exist ... or if else ?
On the other hand , wanted to know if the search process location or take long , to see if I should change this or make a database.
Thanks in advanced.
Image Analyst
Image Analyst 2016년 5월 25일
If that does not work for you, please explain why it doesn't.

댓글을 달려면 로그인하십시오.


Todd Leonhardt
Todd Leonhardt 2016년 5월 25일
The exist function should do what you want:
if 2 == exist(file name)
% Do stuff here
end
  댓글 수: 1
Mario Martos
Mario Martos 2016년 5월 25일
Thanks you very much!
For example it would thus be the structure:
This would be the main function :
function [ ] = Preproceso_Principal ( youtube_url , partitura_xml )
JSFile = strcat ( partitura_xml , '_' , youtube_id , '_' , hashname ) ; % Output JSFile name , hash of that particular xml score .
if 2 == exist ( JSFile ) not do anything because I have it ;
How could indicate using a screen 1 for example, that this condition is met ?
end
And if it does not process the rest of the function to get it.
¿ Directly with that I already search and locate the folder where I 'm working ?
On the other hand , it takes a long time ? That is, if such had js files 500 , much take ? Because if not instead of it making a database

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by