Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: How to copy files in alphabetical order?

  1. #1
    Join Date
    May 2009
    Location
    US
    Posts
    867

    Default How to copy files in alphabetical order?

    I need to copy my music to a portable HDD in alphabetical order. My headunit in my car will only display the folders and files in the order that they were written to the disk so to have any form of logic to the album / track listings they need to be written to the disk in alphabetical order.

    Can anyone suggest how to do this in openSUSE? I know dolphin doesn't do this.
    IBM Thinkpad X60s | Intel L2400 | Intel 945GM | 3GB | openSUSE Tumbleweed
    Dell XPS 13 9360 | openSUSE Leap 42.3

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: How to copy files in alphabetical order?

    I use a script like this to copy a whole tree, feel free to modify it to your taste.

    Code:
    #!/bin/sh
    dest="$1"
    shift
    find "$@" -type f | sort | cpio -pduv --block-size=128 "$dest"
    You call it like this:

    Code:
    cpsorted /media/HDD dir1 dir2 dir3
    Unfortunately it will fail with directories with spaces, homework for you.

    You can also get a program called fatsort which will sort the FAT partition. It must be unmounted.

  3. #3
    Join Date
    May 2009
    Location
    US
    Posts
    867

    Default Re: How to copy files in alphabetical order?

    Thanks. Unfortunately most of my directories have spaces. I'll look at that fatsort app and see how that goes.
    IBM Thinkpad X60s | Intel L2400 | Intel 945GM | 3GB | openSUSE Tumbleweed
    Dell XPS 13 9360 | openSUSE Leap 42.3

  4. #4
    Join Date
    Sep 2008
    Location
    Earl Shilton UK
    Posts
    298

    Default Re: How to copy files in alphabetical order?

    That's a nice script, I'm stealing it. Thankyou for posting it

    My car stereo is the same. Until now (mainly because I am very lazy) I have just copied the songs across one by one.
    Happily using Linux since 1998
    Share & Enjoy

  5. #5
    Join Date
    May 2009
    Location
    US
    Posts
    867

    Default Re: How to copy files in alphabetical order?

    I just tried using fatsort to sort so will see how they have sorted when I plug my drive in tomorrow.
    IBM Thinkpad X60s | Intel L2400 | Intel 945GM | 3GB | openSUSE Tumbleweed
    Dell XPS 13 9360 | openSUSE Leap 42.3

  6. #6
    Join Date
    Jan 2009
    Location
    43.009 N, 73.172 W
    Posts
    189

    Default Re: How to copy files in alphabetical order?

    Quote Originally Posted by suse_tpx60s View Post
    Thanks. Unfortunately most of my directories have spaces. I'll look at that fatsort app and see how that goes.
    You can handle spaces in dir names by quoting them.

    Code:
    "this dir" "that dir" "the other dir"

  7. #7
    Join Date
    Jun 2008
    Location
    Natchez, MS, USA
    Posts
    518

    Default Re: How to copy files in alphabetical order?

    But how will that handle sub directories?
    Free Fractal Wallpapers
    http://wilsonephillips.smugmug.com

  8. #8
    Join Date
    May 2009
    Location
    US
    Posts
    867

    Default Re: How to copy files in alphabetical order?

    Quote Originally Posted by udaman View Post
    You can handle spaces in dir names by quoting them.

    Code:
    "this dir" "that dir" "the other dir"
    I see - that makes sense. The problem is I have around 600 directories so typing them all out like that wouldn't be practical.
    IBM Thinkpad X60s | Intel L2400 | Intel 945GM | 3GB | openSUSE Tumbleweed
    Dell XPS 13 9360 | openSUSE Leap 42.3

  9. #9
    Join Date
    Jan 2009
    Location
    43.009 N, 73.172 W
    Posts
    189

    Default Re: How to copy files in alphabetical order?

    You don't type them in manually, you do it programmatically. In Perl you would open the dir into a variable and use that variable to parse your 600 directories. Like this.

    Code:
    opendir(DIR, $dir) or die "can't opendir $dir: $!";
            while (defined(my $file = readdir(DIR))) {
            next if $file =~ /^\.\.?$/;
            print STDOUT "$dir/$file\n";
            copy("$dir/$file", $BUdir);
            }
        closedir(DIR);

  10. #10
    JosephKK NNTP User

    Default Re: How to copy files in alphabetical order?

    On Mon, 08 Feb 2010 17:36:04 GMT, suse tpx60s <suse_tpx60s@no-mx.forums.opensuse.org> wrote:

    >
    >udaman;2116930 Wrote:
    >> You can handle spaces in dir names by quoting them.
    >>
    >> >

    >Code:
    >--------------------
    > > > "this dir" "that dir" "the other dir"

    >--------------------
    >> >

    >I see - that makes sense. The problem is I have around 600 directories
    >so typing them all out like that wouldn't be practical.


    There must be some slick way of doing

    cd "first dir"
    ls >dirlist

    Recursively throughout an entire tree.

    Midnight commander ought to do this natively as well.

    rsync may be of use here as well.

Page 1 of 3 123 LastLast

Posting Permissions

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