フィルターのクリア

Create and name a directory

106 ビュー (過去 30 日間)
Baba
Baba 2011 年 11 月 8 日
コメント済み: Image Analyst 2017 年 8 月 28 日
Hi
I want to create a subfolder in some folder and name that subfoder as data-"name of the folder". So if folder name is INFO, I want to create a sufolder in the INFO folder named DATA-INFO.
I have:
mkdir('DATA-' what to put here? )
What is the syntax of adding the main folder name to the mkdir subfolder name?
Thanks

回答 (3 件)

Image Analyst
Image Analyst 2011 年 11 月 9 日
I don't recommend ever relying on "pwd" because that could change without you being aware of it, for example by some other badly written function you call. Don't even ask what pwd is if you're compiling your app - it gets complicated. I recommend keeping track of all your folders in variables that you create and control so that you know for certain what they are at all times. So my answer would be something like this that does not depend on pwd at all:
% First, get the name of the folder you're using.
% For example if your folder is 'D:\photos\Info', parentFolder would = 'D:\photos, and deepestFolder would = 'Info'.
[parentFolder deepestFolder] = fileparts(yourFolder);
% Next, create a name for a subfolder within that.
% For example 'D:\photos\Info\DATA-Info'
newSubFolder = sprintf('%s/DATA-%s', yourFolder, deepestFolder);
% Finally, create the folder if it doesn't exist already.
if ~exist(newSubFolder, 'dir')
mkdir(newSubFolder);
end
Note: forward slashes work in both Unix and Windows.
  15 件のコメント
Rohan Maharjajn
Rohan Maharjajn 2017 年 8 月 28 日
@osama Did yo get the answer?? I am also facing the same problem!!
Image Analyst
Image Analyst 2017 年 8 月 28 日
It should be str2double, not str2dobule.

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


Nirmal Gunaseelan
Nirmal Gunaseelan 2011 年 11 月 8 日
You should be creating customized strings using concatenation and passing those strings to mkdir. Current folder name could be obtained by manipulating output of PWD. Eg.
% This puts the entire path of current folder, but you can change as per what you need as the suffix
currFolderName = pwd;
% Create customized string name sub folder
mkdir(['DATA-', currFolderName]);

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 8 日
Folder=pwd
[PathStr,FolderName]=fileparts(Folder)
DataFolder=['DATA-',FolderName]
mkdir(DataFolder)
  1 件のコメント
Stephen23
Stephen23 2016 年 12 月 15 日
Don't use pwd in code like this: it is unreliable. See Image Analyst's answer below.

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

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by