SORU
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ş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • parlophone

    parlophone

    28 ŞUBAT 2006
  • Tom Megalis

    Tom Megalis

    18 NİSAN 2006
  • Top10Series

    Top10Series

    26 Kasım 2008