-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSongFileRenamer.m
81 lines (52 loc) · 1.7 KB
/
SongFileRenamer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function [] = SongFileRenamer()
folder2assess = uigetdir;
cd(folder2assess)
folderDir = dir;
dayNames = {folderDir.name};
dayNames = dayNames(3:end);
% currentFolder = pwd;
%% Delete txt files out of folders
for dayI = 1:length(dayNames)
tempFold = strcat(folder2assess,'\',dayNames{dayI});
cd(tempFold)
txtFilesD = dir('*.log');
txtFiles = {txtFilesD.name};
for ti = 1:length(txtFiles)
delete(txtFiles{ti});
end
end
%% Figure out which folders need renaming
getDayDir = @(x) dir(strcat(folder2assess,'\',x,'\*.wav'));
getDayNames = @(x) {x.name};
get1stDay = @(x) x{1};
getLastDay = @(x) str2double(x{length(x)}(1:5));
% Fix finding wrong filenames
% 1st Check
dayIndex = cell2mat(cellfun(@(x) length(get1stDay(getDayNames(getDayDir(x)))) ~= 9, dayNames,...
'UniformOutput',false));
% 2nd Check
dayIndex2 = cellfun(@(x) ~(getLastDay(getDayNames(getDayDir(x))) == length(getDayNames(getDayDir(x)))), dayNames);
days2assess = unique([dayNames(dayIndex) dayNames(dayIndex2)]);
%%
if isempty(days2assess)
return
else
for i = 1:length(days2assess)
dayofInt = days2assess{i};
cd(strcat(folder2assess,'\',dayofInt))
fdir = dir('*.WAV');
fnames = {fdir.name};
numFiles = numel(fnames);
for i2 = 1:numFiles
getLen = length(num2str(i2));
pad = num2str(zeros(1, 5-getLen));
pad(pad==' ') = '';
newname = strcat(pad,num2str(i2),'.wav');
if strcmp(newname,fnames{i2})
continue
else
movefile(fnames{i2},newname)
end
end
end
end