Copy files specified by the user
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
i have written a code which copies the files from a source to destination after the pushbutton is pressed. Now, i would like to modify the code to work as - only those files must be copied specified by the user in the text box.
For example:
The user specifies 1:10
file number 1 to 10 must be copied.. File1, File2.....File10.
The file name is
S1_ZXK_ABC,
S1_ZXK_CBA,
S2_ZXK_ABC,
S2_ZXK_CBA,
S3_ZXK_ABC,
S3_ZXK_CBA,
S4_ZXK_ABC,
S4_ZXK_CBA,
.
.
.
.
.
S10_ZXK_ABC,
S10_ZXK_CBA
I don't know how to modify the code to suit this. Can anyone please help.
The program is as follows:
function varargout = untitled3(varargin)
% UNTITLED3 M-file for untitled3.fig
% UNTITLED3, by itself, creates a new UNTITLED3 or raises the existing
% singleton*.
%
% H = UNTITLED3 returns the handle to a new UNTITLED3 or the handle to
% the existing singleton*.
%
% UNTITLED3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED3.M with the given input arguments.
%
% UNTITLED3('Property','Value',...) creates a new UNTITLED3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled3_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled3_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled3
% Last Modified by GUIDE v2.5 13-Jan-2012 09:44:41
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled3_OpeningFcn, ...
'gui_OutputFcn', @untitled3_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled3 is made visible.
function untitled3_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled3 (see VARARGIN)
% Choose default command line output for untitled3
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled3 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled3_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function subrange_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
experiment = get(hObject,'String');
% --- Executes during object creation, after setting all properties.
function subrange_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
dest='C:\#source\123';
route='\\MYPC'
src1=dir(fullfile(route,'\data\Group1\*ABC*.mat'));
src2=dir(fullfile(route,'\data\Group1\*CBA*.mat'));
for i=1:length(src1)
r=src1(i,1).name;
srcc=[route '\data\Group1\' r];
copyfile(srcc,dest);
end
for i=1:length(src2)
r=src2(i,1).name;
srcc=[route '\data\Group1\' r];
copyfile(srcc,dest);
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
0 comentarios
Respuestas (1)
Walter Roberson
el 13 de En. de 2012
In pushbutton1_Callback you currently use
src1=dir(fullfile(route,'\data\Group1\*ABC*.mat'));
for i=1:length(src1)
In order to copy only a particular subset of those files, you must order the results of dir() by file name as the first step.
You need to be careful doing that as the file names start with Sn_ where n is a number of variable length. If you were to use sort() on the names, then you would be relying on the relative sort order of the digits compared to the '_' character as you want S1_ S2_ through S10_ to S19_ to sort before S20_ . Unfortunately for you, the character '0' sorts before '_', so S20_ would sort before S2_ .
Thus, you need to extract the number from the string for each src1(K).name and sort that list of numbers, get the sorting order, and apply that to sort src1 in order to put src1 in the order you want. You may wish to consider using regexp() to extract the digit characters, and then str2double() on the resulting cell array to get the numeric values.
Once you have src1 and src2 in sorted order, instead of copying to length(src1) or length(src2), copy only the entries designated by the user input.
0 comentarios
Ver también
Categorías
Más información sobre Graphics Object Properties en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!