Skip to content
Snippets Groups Projects
Commit 973ccb8c authored by Lemmer, Jan's avatar Lemmer, Jan
Browse files

clean commit

parent cb9c58b8
Branches
Tags
No related merge requests found
function [storagePaths] = createFileCopy(filePaths,folderName,storPath,ID,type)
% Creates a copy of the files (can be used for multiple paths in a cell array)
% folderName is the name of the exporting folder
% returns the storage paths were files were stored
if ~iscell(filePaths)
%fixes Issue if Filepath is a char and not a cell array
filePaths = {filePaths};
end
try
storagePaths = cell(numel(filePaths,1));
for i = 1:numel(filePaths)
FileNameAndLocation = filePaths{i};
[~,name,ext] = fileparts(filePaths{i}); % get the extension
switch type
case 'data'
newfile = sprintf([name,ext]); %keep original name
%old behaviour
%sufix = '_data';
%newfile = sprintf([ID, sufix, '_' , num2str(i) ,ext]);
case 'dataCentral'
%keep original name
newfile = sprintf([name,ext]);
case 'script'
sufix = '_script';
newfile = sprintf([ID, sufix ,ext]);
case 'userFcn'
%keep original name
newfile = sprintf([name,ext]);
otherwise
error([type,' is not a valid type for createFileCopy'])
end %switch
RemotePath = fullfile(storPath,folderName, newfile);
% Check if remote file already exists
count = 0;
while isfile(RemotePath) && ismember(type,{'data','dataCentral'})
% Add a Sufix number to new file name
% TODO add more inteligent way then a simple sufix
count = count + 1;
[~,name,ext] = fileparts(RemotePath);
if count < 2
RemotePath = fullfile(storPath,folderName,...
[name,'_',num2str(count),ext]);
else
RemotePath = fullfile(storPath,folderName,...
[name(1:end-length(num2str(count))),num2str(count),ext]);
end
[~, name, ~] = fileparts(RemotePath);
msg = ['Filename ',name,...
' already exists in the data folder' newline,...
' PlotID will add an suffix if you continue.' newline,...
' This can cause serious confusions.'];
warning(msg);
m = input('Do you want to continue, Y/N [Y]:','s');
if ismember(m,{'N','n'})
errorMSG = ['Filename already exists in data folder.' newline,...
' Rename the File and restart PlotID.'];
error();
end
end
copyfile(FileNameAndLocation,RemotePath);
storagePaths{i} = RemotePath;
end
disp([type, ' sucessfully published']);
catch
warning([type,' export was not sucessful'])
if exist('errorMSG')
error(errorMSG);
end
end %try
end %function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment