matlab脚本语言对文件进行批量重命名及生成随机数

一、批量重命名脚本

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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值