File Exchange

image thumbnail

easycopy

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

5 Downloads

Updated 26 Jul 2018

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:
IL_test2.s4p
FEXT_Test4_try2.s4p
NEXT_try3_TEST6.s4p
(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#...")
Test2_IL.s4p
Test4_FEXT_try2.s4p
Test6_NEXT_try3.s4p
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'
easycopy(src,dest);
DONE !
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
-------------------------------------------------------------------------
EXAMPLES AND MOST COMMON USES OF EASYCOPY:
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
wildcard
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
ugins\vstplugins_readme.txt

-------------------------------------------------------------------------
QUESTIONS, COMMENTS, FEEDBACK
Michael Rowlands - v1.0 2017-05-24
Engineering in the 21st century; Make It Easy !
easineering@gmail.com
-------------------------------------------------------------------------

Cite As

Michael Rowlands (2020). easycopy (https://www.mathworks.com/matlabcentral/fileexchange/63417-easycopy), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)

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

Undefined function or variable 'sstr'.

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

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

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

Updates

1.7.0.0

Bug fixes for a few scenarios with wildcards, based on user feedback.

1.6.0.0

Bug fix to avoid crashes in certain scenarios

1.5.0.0

Added 'move' argument to move/rename files and remove the original files.
Can handle arbitrary numbers of * and ? wildcards in both directory and file searches.
Fix some bugs in specific search scenarios.
Consolidated functions for streamlined code.

1.4.1.0

Add support for * and ? wildcards in directories

1.4.0.0

Add support for * and ? wildcards in

1.3.0.0

Added support for large numbers of wildcards

1.2.0.0

Added support for searching extensions using wildcards

1.1.0.0

Added more find and replace features, such that *f???*... source matches f???? destination and removes the unwanted strings.

1.0.0.0

Edited description.

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

Inspired: easyrename