Add same to different paths

I have a folder, which has some excel sheets. These excel sheets are taken as input for my code.
I am using cd and addpath and rmpath functiions to automatically run this script in different folders.
I need to run this code in 5 different folders. Input files in folders are same. There are around 800 input files. I dont want to copy paste these files in all 5 folders.
Is there any way by which I could call the files from one folder as input in all 5 different folders while running code.
I tried using shortcuts , but it did not work.

 採用された回答

Jan
Jan 2013 年 6 月 11 日
編集済み: Jan 2013 年 6 月 11 日

1 投票

You can address a file using the full path:
Folder = 'C:\DataPath'; % Set accordingly
List = dir(fullfile(Folder, '*.xlsx');
for iList = 1:length(List)
File = fullfile(Folder, List(iList).name);
... Operations with the file here
end
Now accessing the files is independent from th current folder.

7 件のコメント

Priya
Priya 2013 年 6 月 11 日
Thanks.
However, I cant apply for loop for list as I am calling the input file at different parts of my code.
Priya
Priya 2013 年 6 月 11 日
Is there no way, by which I can access these files from anywhere and call them anywhere in my code ?
Jan
Jan 2013 年 6 月 11 日
@Priya: The shown method is reliable and allows to access files at any location. Using full path names is the recommended and standard method to access files.
If you need something else, I assume you did not explain the problem clearly enough yet. What does "call the files anywehere" mean?
Priya
Priya 2013 年 6 月 12 日
Actually I have .pdb files as input which i read through pdbread function.
I have around 60 different codes which read same .pdb files.
I already have a for loop to read those files in each of the 60 codes.
But the problem is I need to add the folders containing those .pdb files to my current path.
I have made 60 folders to store results of 60 different codes. However, I have to copy paste the folder containing .pdb files in all 60 folders, which is consuming a lot of space.
So , is there any way, by which without using for loop, I can use .pdb files as input from single folder at certain location without duplicating this folder in all 60 different folders.
Iain
Iain 2013 年 6 月 12 日
copy the files to your current directory?
give your pdbread function the full filename (which includes path)
Jan
Jan 2013 年 6 月 12 日
@Priya: I still do not understand, why you have to copy the files or why they must be found in the current folder. I have shown you already, how you can access a file in a specific folder using the folder's name and the fullfile() command. Please explain why you do not want to use the full path name to the files.
And of course yo do not have to use a FOR loop. It appears in my example code only as example. The main point is the fullfile().
Priya
Priya 2013 年 6 月 12 日
@Jan and @lain :Thanks, I combined both suggestions and it worked

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSearch Path についてさらに検索

質問済み:

2013 年 6 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by