File Exchange

image thumbnail


version (23.2 KB) by Michael Rowlands
Convenient way of copying and renaming large groups of files using lists and wildcards.

1 Download

Updated 26 Jul 2018

View Version History

View License

This function was written to solve a particular filename problem, then was expanded to do some
other useful things. I had a bunch of measured files from the lab named:
(Notice the mix of upper and lower case letters, plus the "try.." notes
for some measurements. )
There is a customer-required tool that takes these files and makes a report, and it can only read
files named like this: (Each file must start with "Test#...")
There are hundreds of lab measurements with imperfect labels.
I was looking for an easy way to rename all the files, so I
wrote this function.
src = '\\testlab\product_xyz\data\*test?*.s4p'
dest = \\testlab\product_xyz\data_renamed\*!bTest?*.s4p'
This scenario uses wildcards, plus the "!b" custom code. More on that, later in EXAMPLES and in the ADVANCED USERS section.
This function takes a list of source files and a list of destination
filenames and copies the source to the corresponding destination.
source = single filename or list of files
dest = single filename or list of files
sourcedir = source directory for all the source file list
destdir = destination directory for all the dest file lists
sourcelist_fullpath = { 'c:\users\mjrowlands\desktop\NOTES.txt' 'c:\users\mjrowlands\desktop\.condarc' };
destlist_fullpath = { 'c:\users\mjrowlands\desktop\n2.txt' 'c:\users\mjrowlands\desktop\condy.bat' };
sourcelist_relative = { 'desktop\NOTES.txt' 'desktop\.condarc' };
destlist_relative = { 'desktop\n2.txt' 'desktop\condy.bat' };
source_basedir = 'c:\users\mjrowlands'; for use with sourcelist_relative
dest_basedir = 'c:\users\mjrowlands\desktop2'; for use with destlist_relative
Generally, a blank argument ('' or {} or []) gives the user the typical default settings.
INPUT: easycopy
RESULT: displays these help instructions
INPUT: easycopy(sourcelist_fullpath,destlist_fullpath)
RESULT: This is the most basic form of easycopy.
Takes the sourcelist and copies files 1:1 to the destlist.
Copying c:\users\mjrowlands\desktop\NOTES.txt
To c:\users\mjrowlands\desktop\n2.txt
Copying c:\users\mjrowlands\desktop\.condarc
To c:\users\mjrowlands\desktop\condy.bat
***************** ADVANCED USERS: ****************************
Wildcard Rules:
The * and ? wildcards are supported in the source and dest file lists and behave as the basic windows wildcards.
* = match anything, ? = match any one character
If the source has wildcards, then the dest must be blank, or a single
entry, or contain the same wildcards, or must match the length of the list of found files in the
A user may match a source list of one entry, with a wildcard, with a
multi-entry dest list, with no wildcards, if the dest list length has
exactly the same number of entries that the source list matches.
The source and dest must have the same number of each type of wildcard.
For instance if source is 'c:\users\mjrowlands\desktop\a*abc?*.txt' then
dest must have exactly two * and one ?.
The dest argument also supports !b and !e which force the matching wildcards to the
beginning of the destination string (See the story at the beginning of the help text, to see why this feature is useful)
If there's one argument, the contents of the file will be read and each row of the
file will be run as an easycopy command.
Then the exact source and destination file lists from the columns of
the file, with the first row ignored as a header. Supported formats are .txt,.csv and .xlsx
.txt is read as tab-delimited text
.csv is read as comma delimited
.xlsx is read as standard excel format

Michael Rowlands - v1.0 2017-05-24
Engineering in the 21st century; Make It Easy !

Cite As

Michael Rowlands (2021). easycopy (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)

Michael Rowlands

Thanks for the feedback. sstr bug fixed in ver 1.7.

Agustinus Ribal

Undefined function or variable 'sstr'.

Michael Rowlands

Thanks for the feedback. I fixed the bug in vet 1.6

Douglas Fitzpatrick

Not working for me:
Undefined function or variable 'removeblanks'.

Error in buildlist>extractmatch (line 1194)
sstr = removeblanks(strsplit(searchstring,'*'));

Davi Correia

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: easyrename

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!