-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathcheck_for_duplicate.m
36 lines (34 loc) · 1.49 KB
/
check_for_duplicate.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
function newfilename = check_for_duplicate(outfile, outpath)
% Check if the output file name matches any of the current file names in
% the directory and then prompt for a rename, overwrite, or automatic
% rename
y=0;
thedir = dir(outpath);
newfilename = outfile;
%get the length of the directory to figure out how far to count in
for y = 1:length(dir)
if ( (strcmp(outfile, thedir(y).name)) == 1)
newname = questdlg('Name of File?', 'Name of File', ...
'Rename', 'Overwrite', 'Automatically Name', 'Automatically Name');
switch newname
case 'Rename'
newfilename = char(inputdlg ('Rename the file'));
%for files that are the same name, Autoname just adds a (A)
%before the .x.wav part, and if there already is an (A),
%then another 'A' is added in between the parenthesis
case 'Automatically Name'
for a = 1:length(thedir(y).name)
if thedir(y).name(a) == '('
thedir(y).name = strrep(thedir(y).name, ').x.wav', 'A).x.wav');
newfilename = thedir(y).name;
break;
else if thedir(y).name(a) == '.'
thedir(y).name = strrep(thedir(y).name,'.x.wav', '(A).x.wav');
newfilename = thedir(y).name;
break;
end
end
end
end
end
end