#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Need help Moving files to corresponding folder based on filename


    I am trying to move files to a corresponding folder based on their filename. There are 3 identifiers, the genre i.e. "DRAMA", the director i.e. "von Trier", and the movie name i.e. "Melancholia". So the file "DRAMA von Trier Melancholia" would need to be moved to say, C:/shared/com/movies/DRAMA/Melancholia/von Trier. There are many files that need to be moved, so I would rather not hard code the locations/do it 1 by 1. Here is what I have so far which lists all the files I want moved, but does not actually move them.

    Code:
    import os
        import shutil
        import fnmatch
    
        for dirpath, dirs, files in os.walk('C:/shared/com/movies/'):
            print dirpath
            print dirs
            print files
            for filename in files:
                if filename.endswith('*.mov'):
                    shutil.move('') #not sure how to code this to have it move based on paramaters rather than hard coding it, I imagine some kind if boolean if..then coding might work but I don't know how to set that up.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,966
    Rep Power
    481
    What is the input to your program?

    How many movies are named Melancholia?

    Is / valid as a DOS path separator?

    And what is your question?

    C:/shared/com/movies/DRAMA/Melancholia/von Trier
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by b49P23TIvg
    What is the input to your program?

    How many movies are named Melancholia?

    Is / valid as a DOS path separator?

    And what is your question?

    C:/shared/com/movies/DRAMA/Melancholia/von Trier
    There are 12 movies named Melancholia - many of the files contain some of the same identifiers, but none of them have all of the same identifiers. I.e. there can be a file named DRAMA Steinberg Melancholia and a file named DRAMA von Trier Melancholia. But not two files named DRAMA Steinberg Melancholia.

    / works fine in DOS

    My question is if there is a way to have the code look through all of my files in C:/shared/com/movies/ , look at the name of the files, then move them to the correct folder path that contains the same identifiers. I.e. DRAMA Steinberg Melancholia.mov would be moved to C:/shared/com/movies/DRAMA/Melancholia/Steinberg.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,966
    Rep Power
    481
    So you've got this file named
    DRAMA von Trier Melancholia
    How do you distinguish between

    DRAMA von/Trier/Melancholia
    DRAMA/von Trier/Melancholia
    DRAMA/von/Trier Melancholia

    Things are worse if the genre is
    Detective Story
    Courtroom Drama
    science fiction
    social drama
    black comedy

    and the movie title is
    Originally Posted by http://mentalfloss.com/article/23458/quick-10-10-longest-movie-titles#ixzz2JZaHh7bw
    1. The Incredibly Strange Creatures Who Stopped Living and Became Mixed-Up Zombies!!? (11 words)
    2. Borat: Cultural Learnings of America for Make Benefit Glorious Nation of Kazakhstan (12 words)
    3. Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb (13 words)
    4. Don't Be a Menace to South Central While Drinking Your Juice in the Hood (14 words)
    5. Who is Harry Kellerman and Why is He Saying Those Terrible Things About Me? (14 words)
    6. The Lemon Grove Kids Meet the Green Grasshopper and the Vampire Lady from Outer Space (15 words)
    7. Oh Dad, Poor Dad, Mama's Hung You in the Closet and I'm Feeling So Sad (15 words)
    8. The Saga of the Viking Women and their Voyage to the Waters of the Great Sea Serpent (17 words)
    9. Those Magnificent Men in Their Flying Machines, or How I Flew from London to Paris in 25 Hours 11 Minutes (20 words)
    10. The Fable of the Kid Who Shifted His Ideals to Golf and Finally Became a Baseball Fan and Took the Only Known Cure (23 words)

    and a bonus:

    11. Night of the Day of the Dawn of the Son of the Bridge of the Return of the Revenge of the Terror of the Attack of the Evil, Mutant, Alien, Flesh Eating, Hellbound, Zombified Living Dead Part 2: In Shocking 3-D (41 words)
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo