16 NİSAN 2010, Cuma
Nasıl tüm dosyaları almak için MATLAB belirli bir dizin altında?
D:\dic
altındaki tüm dosyaları almak ve onları daha fazla döngü için ayrı ayrı işlemek gerekiyor.
MATLAB destek operasyonları bu tür mu?
PHP,Python gibi diğer komut yapılabilir...
CEVAP
16 NİSAN 2010, Cuma
Burada belirli bir dizin ve tüm alt dizinler yinelemeli arama fonksiyonu, bulduğu tüm dosya isimlerinin toplama:
function fileList = getAllFiles(dirName)
dirData = dir(dirName); %# Get the data for the current directory
dirIndex = [dirData.isdir]; %# Find the index for directories
fileList = {dirData(~dirIndex).name}'; %'# Get a list of the files
if ~isempty(fileList)
fileList = cellfun(@(x) fullfile(dirName,x),... %# Prepend path to files
fileList,'UniformOutput',false);
end
subDirs = {dirData(dirIndex).name}; %# Get a list of the subdirectories
validIndex = ~ismember(subDirs,{'.','..'}); %# Find index of subdirectories
%# that are not '.' or '..'
for iDir = find(validIndex) %# Loop over valid subdirectories
nextDir = fullfile(dirName,subDirs{iDir}); %# Get the subdirectory path
fileList = [fileList; getAllFiles(nextDir)]; %# Recursively call getAllFiles
end
end
Yukarıdaki tasarrufu bir yerde MATLAB yolda fonksiyonu sonra, şu şekilde arayın:
fileList = getAllFiles('D:\dic');
Bunu Paylaş:
Nasıl üretilen kod gibi belirli bir di...
Nasıl Gıt belirli revizyon tek bir dos...
Nasıl Gıt bir çalışma dizini içine boş...
Belirli dosyaları hariç tar dizin kabu...
Nasıl bir OpenSSL almak için .pem dosy...