Class Work Gadgets

This is a collection that will be continuously updated, if there are enough, consider opening a column. Not a computer major, just a hobby. The tools are mainly limited to: python, matlab, labview. You can also use a bull knife to kill chickens.

Create folders in batches

Introduction: It is used to organize the materials of each person, and supports generating folders based on the roster.
Tool: Matlab

clc;clear;
filePath = 'C:\data.xlsx';
Goal = 'C:\Users\Administrator\Desktop\Work'
txt = readtable(filePath,'Range','A:A','ReadVariableNames',false);
txt = table2array(txt);
num = length(txt);
 for i = 1:num 
     goal = [Goal,'\',txt{i}] 
     mkdir(goal);
     %disp(goal)
 end

Goal: the parent folder of the folder to be created
filePath: the roster file path

You can also use the command line in the parent folder: "tree /f" to check the files in all folders at the same time.

Rename image files by type in batches

Introduction: It is used to organize the screenshot files of each person, and supports renaming according to tags.
Tool: The Matlab
  book is continued from the previous chapter. We can also rename the collected image files according to their type. First add the target folder in the FilePath statement, and then the program will read all the picture files [^1] in the name subfile, and display them from left to right. We only need to define the type of pictures contained in the tag statement, and then enter the sequential sequence of the corresponding pictures in the command line to rename the pictures.
  For example:
Please add a picture description
insert image description here
  only two image types are displayed here; the actual working logic is that there must be 12 and 3 as optional types. So the logic of the program here is also the same: if the picture is 2, show both types. If 3, join the optional type.

  There are still many problems in this design that need to be improved, or this tool has certain limitations:
1. It only supports pictures; 2. The logic of label display is not comprehensive; 3. There is no interrupt operation; 4. It does not support jpeg (if this problem is in actual Encountered at work and will come back to improve)

%%初始化
clc;clear;
tag = {'行程卡','健康码','承诺书'};
FilePath = 'C:\Users\Administrator\Desktop\返校材料截图';
showtext =[];

%%获得数据文件夹目录
File = dir(FilePath); 
namedata = {File.name};namedata(1)=[];namedata(1)=[];totalnum = length(namedata);

%%到个人文件夹进行操作
for a = 1:totalnum
    nowloca = [FilePath,'\',namedata{a}];
    File = dir(nowloca);
    picdata = {File.name};picdata(1)=[];picdata(1)=[];num = length(picdata);
    
    %%显示图片
    for i = 1:num
        picloca = [nowloca,'\',picdata{i}];
        pic = imread(picloca); subplot(1,num,i);imshow(pic)
        showtext = strcat(showtext,tag{i},'//');
    end
    
    %%打标
    showtext = strcat(showtext,'输入序号:');
    text(1,4,namedata{a},'FontSize',14);
    sort = num2str(input(showtext));
    close all
    showtext =[];
    
    %%文件重命名操作
    for i = 1:num
       picloca = [nowloca,'\',picdata{i}];
       newname = strcat(nowloca,'\',namedata{a},tag{str2num(sort(i))},picloca(end-3:end));
       % disp(picloca) %disp(newname)
       movefile(picloca,newname); 
    end
    
end

  The name of the new file will be composed of subfolder name + image type name; for example, /Xiaoming/Xiaoming Health Code.jpg
  Summary: This tool ignores generality well, and its main purpose is to solve the problem at hand. Welcome to DIY according to your own situation.

Guess you like

Origin blog.csdn.net/qq_49003248/article/details/123361761