Results 1 to 7 of 7

Thread: Script file to copy files

  1. #1

    Default Script file to copy files

    Dear all,
    I have an external hard disk with lots of big files and a lot of small matlab script files .m.

    I would like to grab all the files inside that harddisk that have the .m extension or the *.mat file extension (both are matlab files).

    Of course this is a
    -first-find the *.m files script and
    -then copy the files into the hard disk.

    What I do not know is how I can also keep the structure of the folders containing the *.m and *.mat files when I will copy them in my local hard disk.

    As this external hard disk contains 2TB of data it is not possible to copy all the files first and then remove the unnecessary.
    So I have to find and copy only the files I need but with also keeping the tree structure that the external hard disk has .

    Can you help me find out an easy way to do that?

    Regards
    Alex

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,871

    Default Re: Script file to copy files

    Of course it should have been iin Programming/Scripting. But I am not moving it because of the wrath of the NTTP users.
    Last edited by hcvv; 06-Apr-2011 at 06:37.
    Henk van Velden

  3. #3
    Join Date
    Aug 2008
    Location
    Behind the 8 ball
    Posts
    116

    Default Re: Script file to copy files

    This should get you started, I added echos so you can see what the script will be doing. Once you are happy with the script remove the echos

    Code:
    cd /your/external/drive
    for FILE in $(find . -type f | grep -e ".m$\|.mat$")
    do
       THISDIR=`dirname ${FILE} | sed s/"^."//`
       echo "mkdir -p /local/drive${THISDIR}"
       echo "cp ${FILE} /local/drive${THISDIR}"
    done
    Good luck,
    Hiatt

  4. #4

    Default Re: Script file to copy files

    I am sorry for that
    what are the nttp users?

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,871

    Default Re: Script file to copy files

    Quote Originally Posted by alaios View Post
    I am sorry for that
    what are the nttp users?
    Never mind, I shouldn't have posted that here. My fault. The only thing is that you are requested to post things about programming/scripting in the correct sub-forum next time. The people who love solving problems like yours are lurking there!
    Henk van Velden

  6. #6
    Join Date
    Jun 2008
    Location
    Earth - Denmark
    Posts
    10,730

    Default Re: Script file to copy files

    On 04/06/2011 05:06 PM, hcvv wrote:
    >
    >> what are the nttp users?

    >
    > Never mind


    ok, i will answer him:

    nntp users are those of a naturally superior intellect, extremely good
    looking, friendly demeanor and impeccable manner....like myself ;-)

    ok here is the truth: nntp is just a different method of accessing these
    forums...it is a much older method and unlike the web experience (with
    colors, and blinkies, and colored text etc etc) it is pretty
    plain...just plain text mostly...like non-html email..

    some people find nntp a quicker way to ask or answer/help, others find
    it not only dull but far slower to use..

    it is all in what you are used to..

    unfortunately, some folks wanna generalize all nntp (or http) users to
    be cut from the same cloth.....which ain't the case because i heard
    someone say that they met an ugly nntp user---but, i don't believe it!!

    ;-)

    by the way Alex, hcvv wasn't 'mad' at you, he was just giving me a hard
    time...in jest...and you misunderstood..

    --
    CAVEAT: http://is.gd/bpoMD [NNTP via openSUSE 11.3 + KDE4.5.5 +
    Thunderbird3.1.8] Can you believe it? This guy Ralph wins $181 million
    in the lottery last Wednesday, and then finds the love of his life just
    2 days later. Talk about LUCK!

  7. #7

    Default Re: Script file to copy files

    I know that he was not mad with me
    Cheers!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •