フィルターのクリア

How to read part of folder

4 ビュー (過去 30 日間)
DuckDuck
DuckDuck 2014 年 12 月 12 日
編集済み: Guillaume 2014 年 12 月 12 日
I have my data saved into folders based on time of creation. the structure is like this:
folder: 05_dec._2014_08-15-03.331_GMT+00-00
files: OneName_05_dec._2014_08-15-03.331_GMT+00-00.txt
AnotherName_05_dec._2014_08-15-03.331_GMT+00-00.txt
JetAnotherName_05_dec._2014_08-15-03.331_GMT+00-00.txt
How can i do so that every time i add a folder, i'll need to only give the folder name and it will read file names based on some schema.
for example
First = csvread('OneName_whatever_folder_name.txt')
Second = csvread('AnotherName_whatever_folder_name.txt');

回答 (2 件)

Orion
Orion 2014 年 12 月 12 日
you can use fullfile
Folder = 'C:\users\....\05_dec._2014_08-15-03.331_GMT+00-00'; % put your own folder path
File = 'OneName_whatever_folder_name.txt';
csvread(fullfile(Folder,File))
  1 件のコメント
DuckDuck
DuckDuck 2014 年 12 月 12 日
I want to eleminate writing the file name every time i need to access a folder with files. Because each folder has the same nr of files but they differ from timestamp in their name.

サインインしてコメントする。


Guillaume
Guillaume 2014 年 12 月 12 日
編集済み: Guillaume 2014 年 12 月 12 日
How about:
foldername = 'whatever'; %adjust to folder name, your input.
basepath = 'C:\somewhere\ondisk'; %adjust as required. A constant.
filesinfolder = dir(fullfile(basepath, foldername, sprintf('*_%s.txt', foldername)));
filecontent = cell(numel(filesinfolder), 1);
for filecount = 1 : numel(filesinfolder)
filecontent{filecount} = csvread(fullfile(basepath, foldername, filesinfolder(filecount).name));
end
  2 件のコメント
DuckDuck
DuckDuck 2014 年 12 月 12 日
I get empty filesinfolder and filescontent!!!
Guillaume
Guillaume 2014 年 12 月 12 日
編集済み: Guillaume 2014 年 12 月 12 日
I've not understood your pattern then, I thought the file names were just the folder name preceded by something and an underline _ and followed by .txt. If that's not the case, then yes, filesinfolder will be empty.
What does the following outputs?
d = dir(fullfile(basepath, foldername));
fullfile(foldername, {d.name}')

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by