一、批量重命名脚本
function FileChange_Cha(a_Path, a_Suffix, a_newName)
%('D:\xxx\1_Projects\1_xxx-A1\6_Script\demoCopy','.h','dserss')
Suffix_fix = strcat('*',a_Suffix);
newName_fix = strcat(a_Path, '\');
fileFolder=fullfile(a_Path);
dirOutput=dir(fullfile(fileFolder, Suffix_fix));
fileNames={dirOutput.name}';
for c_index = 1:length(fileNames)
%fprintf(fileNames{c_index, 1});
%fprintf('\n');
%fprintf('index = %d\n',c_index);
oldname_path = strcat(newName_fix, fileNames{c_index, 1});
newname_path = strcat(newName_fix, strcat(strcat(a_newName, num2str(c_index)), a_Suffix));
%fprintf(newName_fix);
%fprintf('\n');
movefile(oldname_path, newname_path);%rename the file
end
end
调用方法:
FileChange_Cha('D:\xxx\1_Projects\1_xxx\6_Script\demoCopy','.h','dserss')
二、生成随机数脚本
function [outputArg1] = untitled4(inputArg1,inputArg2)
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
%inputArg1: the number of "random number"
%inputArg2: the range of "random number"
sortArray = sort(round(rand(1,inputArg1)*inputArg2));
if(inputArg1 <= 0)
errordlg('The enter parameter is wrong !!!','error');
return;
else
outputArg1 = sortArray( randi(inputArg1) );%(double(round(rand(1,1)*inputArg1)));
end
end
调用方法:
x = untitled4(10, 100)