Code covered by the BSD License  

Highlights from
Bulk File Rename

image thumbnail

Bulk File Rename

by

 

GUI Renames multiple files within a folder with same extension

FileRename_Utility(varargin)
function varargout = FileRename_Utility(varargin)
% FILERENAME_UTILITY M-file for FileRename_Utility.fig
%      FILERENAME_UTILITY, by itself, creates a new FILERENAME_UTILITY or raises the existing
%      singleton*.
%
%      H = FILERENAME_UTILITY returns the handle to a new FILERENAME_UTILITY or the handle to
%      the existing singleton*.
%
%      FILERENAME_UTILITY('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FILERENAME_UTILITY.M with the given input arguments.
%
%      FILERENAME_UTILITY('Property','Value',...) creates a new FILERENAME_UTILITY or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before FileRename_Utility_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to FileRename_Utility_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 FileRename_Utility

% Last Modified by GUIDE v2.5 27-Oct-2012 21:50:37

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @FileRename_Utility_OpeningFcn, ...
                   'gui_OutputFcn',  @FileRename_Utility_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 FileRename_Utility is made visible.
function FileRename_Utility_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 FileRename_Utility (see VARARGIN)

% Choose default command line output for FileRename_Utility
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
set(handles.statictxtdir,'string',pwd);
%set(handles.btnfileext,'enable','off');

% UIWAIT makes FileRename_Utility wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = FileRename_Utility_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;


% --- Executes on button press in btnfileext.
function btnfileext_Callback(hObject, eventdata, handles)
% hObject    handle to btnfileext (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[extension] = getextension(get(handles.statictxtdir,'string'));
set(handles.lstfilename,'string',extension);
% filehandle = guihandles(handles.lstfilename);
% filehandle.filelist = files;
% guidata(handles.lstfilename,filehandle);




% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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 btngetdir.
function btngetdir_Callback(hObject, eventdata, handles)
% hObject    handle to btngetdir (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
dirname = uigetdir;
set(handles.statictxtdir,'string',dirname);
%set(handles.btnfileext,'enable','on');

% --- Executes on button press in btnrename.
function btnrename_Callback(hObject, eventdata, handles)
% hObject    handle to btnrename (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
strings = get(handles.lstfilename,'string'); % get the list of strings 
%var = get(handles.lstfilename,'value');
lstselection = strings{get(handles.lstfilename,'value')};
% data = guidata(handles.lstfilename);
filestruct = GetFileName(get(handles.statictxtdir,'string'));
clear data.filelist;
renamefile(filestruct,get(handles.editfilename,'string'),lstselection,get(handles.statictxtdir,'string'))
set(handles.txtstaticcomplete,'string',['File Name with extension' ' ' lstselection ' ' 'Renamed']);



function editfilename_Callback(hObject, eventdata, handles)
% hObject    handle to editfilename (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 editfilename as text
%        str2double(get(hObject,'String')) returns contents of editfilename as a double


% --- Executes during object creation, after setting all properties.
function editfilename_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editfilename (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 selection change in lstfilename.
function lstfilename_Callback(hObject, eventdata, handles)
% hObject    handle to lstfilename (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns lstfilename contents as cell array
%        contents{get(hObject,'Value')} returns selected item from lstfilename


% --- Executes during object creation, after setting all properties.
function lstfilename_CreateFcn(hObject, eventdata, handles)
% hObject    handle to lstfilename (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox 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

Contact us