MATLAB: Check for a word check for a word I need to check if the current folder name contains words: YES or DYES. such that: if it contains YES: a=1 if it contains DYES: a=2 code I'm starting with: Folder=pwd; [PathStr,FolderName]=fileparts(Folder); Best Answer if strfind(FolderName, 'YES'); a = 1; endif strfind(FolderName, 'DYES'); a = 2; endWhat if the folder name contains both? Or neither? What if the folder name contains the word but in lower case? Related SolutionsMATLAB: How to rename images from a series of folder mainDirectory = 'C:\Users\md\Desktop\NewFolder';subDirectory = dir([mainDirectory '/N*']);for m = 1 : length(subDirectory)subFolder = dir(fullfile(mainDirectory, subDirectory(m).name,'*.tif'));fileNames = {subFolder.name}; for iFile = 1 : numel( subFolder ) newName = fullfile(mainDirectory, subDirectory(m).name, sprintf( 'D_1_20%2d.tif',(14-iFile) ) ); movefile( fullfile(mainDirectory, subDirectory(m).name, fileNames{ iFile }), newName ); end end MATLAB: How to copy and rename files in a different folder Try this:% First create the folder B, if necessary.outputFolder = fullfile(pwd, 'B')if ~exist(outputFolder, 'dir') mkdir(outputFolder);end% Copy the files over with a new name.inputFiles = dir( fullfile('*.txt') );fileNames = { inputFiles.name };for k = 1 : length(inputFiles ) thisFileName = fileNames{k}; % Prepare the input filename. inputFullFileName = fullfile(pwd, thisFileName) % Prepare the output filename. outputBaseFileName = sprintf('%s_T.txt', thisFileName(1:end-4)); outputFullFileName = fullfile(outputFolder, outputBaseFileName) % Do the copying and renaming all at once. copyfile(inputFullFileName, outputFullFileName);end Related QuestionSearch folders/paths with strfind: how to do excluding searchCreate folders using matlabHow to create a list of files of the defined typ that are included in the folderHow to rename multiple files located in subfolders within a main folder
Best Answer