Need help with simple python script (renaming and moving folder)

I have this script for use with sabnzbd, what it does is rename all folders in the desired directory, replacing any spaces with dots (example: Movie 2011 HD -> Movie.2011.HD).
#!/usr/bin/env python2
workdir = '/media/stuff/movies' #### CHANGE this line to your movie directory
for path, dirnames, filenames in os.walk(workdir):
print "path:", path
for dirname in dirnames:
if dirname.find(' ') > -1 :
# Yes, a space in the directory name, so replace it:
newname = dirname.replace(' ','.')
fulldirname = path + '/' + dirname
fullnewname = path + '/' + newname
print "Rename" , fulldirname, " ", fullnewname
os.rename(fulldirname, fullnewname)
What I would like it to do is 1. rename only the movie I run the script on (instead of /media/stuff/movies as above, the entire movie folder), and then 2. move the movie into /media/stuff/movies. Or vice versa! (I'd just prefer not to have it run on the entire movie directory).
Appreciate any help!

Just my two cents:
I would not use walkdir but as usual a combination of find and python.
A simplified version of the script could look like this:
#!/usr/bin/python
# -*- coding: utf8 -*-
import os, shutil
# Define target dir
target_dir = "/media/stuff/movies/"
# Loop through all found files
for source_file in os.popen ("find ."):
# Remove \n
source_file = source_file[:-1]
extension = source_file[-3:]
# Only process video files
if (extension == 'mkv') or (extension == 'avi') or (extension == 'mp4'):
target_file = source_file.split('/')
target = target_file[len(target_file)-1]
target = target.replace(' ','.')
shutil.copy (source_file, targetdir + target)
Of course you might first want to print out instead of really copy files.

Similar Messages

  • [SOLVED] Need help with simple a script.

    Hello, Iam searching for a small script that sorts my folders in alphabetical order.
    I want the script to create folder from A to Z and then move every folder that begins with A into the A folder etc etc..
    I really hope anyone understands what im searching for here.
    Last edited by nikihr (2009-09-01 20:25:33)

    scragar wrote:
    brisbin33 wrote:
    be careful, mv $I* will pick up your freshly created directory too;
    i'd `mkdir ./sorted/$I` instead, then `mv ./sorted/* ./ && rm -r ./sorted` at the end.
    you could also use
    find ./ -maxdepth 1 -iname "$I*" -exec mv {} ./sorted/ \;
    to do the actual move*
    *note: untested .
    While my `mv` code will throw an error the error will not stop the moving of the files, you'll just get 26 messages about being unable to move the directory to itself. I could probably find a way to avoid this that doesn't require the use of find(which I personally dislike) or a second dir, probably just using a file prefix like "_" or something. It would only be a small edit:
    #!/bin/bash
    for I in {a..z}; do
    echo "Moving $I";
    mkdir "_$I";
    echo "mv $I* \"$(echo $I | tr [:lower:] [:upper:])\"* _$I/";
    # mv $I* "$(echo $I | tr [:lower:] [:upper:])"* "_$I/";
    mv "_$I" $I
    done
    well, i have to politely disagree:  one, invoking find once is much better IMHO than mv with tr in a subshell.  and two, my ./sorted/ idea adds one additional mv command and one additional rm command where you're _$I suggestion added 26 additional mv commands....  just sayin'
    but we could also paint the bikeshed blue. .
    anyways, i think the OP's got more than he bargained for, hopefully we'll see a [SOLVED] on this one soon.

  • Need help with how to reset bios and admin password to reformat hard drive in 8440p elitebook.......

    need help with how to reset bios and admin password to reformat hard drive in 8440p elitebook? removal of cmos, resetting laptop, using cccleaner, windows password recovery and hiren's was noneffective, any help is appreciated. thanks

    Hi,
    As your notebook is a business class machine, security is more stringent - the password is stored in non-volatile memory and there are no 'backdoor' passwords.  Your best option would be to contact HP regarding this.
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

  • [solved]Need help with a bash script for MOC conky artwork.

    I need some help with a bash script for displaying artwork from MOC.
    Music folders have a file called 'front.jpg' in them, so I need to pull the current directory from MOCP and then display the 'front.jpg' file in conky.
    mocp -Q %file
    gives me the current file playing, but I need the directory (perhaps some way to use only everything after the last  '/'?)
    A point in the right direction would be appreciated.
    thanks, d
    Last edited by dgz (2013-08-29 21:24:28)

    Xyne wrote:
    You should also quote the variables and output in double quotes to make the code robust, e.g.
    filename="$(mocp -Q %file)"
    dirname="${filename%/*}"
    cp "$dirname"/front.jpg ~/backup/art.jpg
    Without the quotes, whitespace will break the code. Even if you don't expect whitespace in any of the paths, it's still good coding practice to include the quotes imo.
    thanks for the tip.
    here it is, anyhow:
    #!/bin/bash
    filename=$(mocp -Q %file)
    dirname=${filename%/*}
    cp ${dirname}/front.jpg ~/backup/art.jpg
    then in conky:
    $alignr${execi 30 ~/bin/artc}${image ~/backup/art.jpg -s 100x100 -p -3,60}
    thanks for the help.
    Last edited by dgz (2013-08-29 21:26:32)

  • Need Help With Simple ABAP Code

    Hello,
    I'm loading data from a DSO (ZDTBMAJ) to an Infocube (ZCBRAD06). I need help with ABAP code to some of the logic in Start Routine. DSO has 2 fields: ZOCTDLINX & ZOCBRDMAJ.
    1. Need to populate ZOCPRODCD & ZOCREFNUM fields in Infocube:
        Logic:-
        Lookup /BI0/PMATERIAL, if /BIC/ZOCBRDMAJ = /BIC/OIZOCBRDMAJ
        then /BIC/ZOCPRODCD = ZOCPRODCD in Infocube
               /BIC/ZOCREFNUM = ZOCREFNUM in Infocube         
    2. Need to populate 0G_CWWTER field in Infocube:
        Logic:
        Lookup /BIC/PZOCTDLINX, if /BIC/ZOCTDLINX = BIC/OIZOCTDLINX
        then G_CWWTER = 0G_CWWTER in Infocube.
    I would need to read single row at a time.
    Thanks!

    I resolved it.

  • Need help running a Python script when DVD inserted

    We had an intern that created a custom Python script to rip our old event recording DVDs back to a digital format. The script creates a JSON description file and asks a set of questions to create the metadata in the JSON file (e.g. Date of event).
    The way the intern set this up was that you'd click on the Python script which would open a terminal window where you fill in the metadata. It then asks if the DVD is in the computer. At this point you place the DVD in. A few seconds later, the Python script notices the DVD and proceeds to rip the DVD at our specific file size requirements along with the inputted metadata.
    We then upgraded the Mac from Mountain Lion to Lion and the script stopped working. Our intern has since left. I have now moved the Python script onto my Mountain Lion Mac. The intern's last message to me was that he had written an AppleScript that ran when the DVD was inserted which then referred to the Python script. The intern has since stopped replying to emails.
    This is a very important project that I would like to continue. Any help would be greatly appreciated!

    well, oddly, that should never have worked. 
    Try this:  open the applescript editor, copy in the following line:
    tell application "Terminal"
              do script "python /Users/medialab/dvddrip rename"
              activate
    end tell
    Save it, making sure that the 'File Format' pull down says Script (the new file will have a '.scpt' extension). You'll be able to select that file in the cd/dvd preferences.
    I assumed that you wanted this to open in terminal so that you can enter options on the command line. If that's not correct, let me know.

  • Need help with simple XML validation

    I am new to Spry and need some help creating a simple
    validation. There is a form field which must not contain a value
    already in the database. I have a script which accepts a parameter
    and returns a boolean result. Here is the XML:
    <samples>
    <sample>
    <ISFOUND>0</ISFOUND>
    </sample>
    </samples>
    1. How do I call this script when the form field changes and
    pass the form value as the parameter?
    2. How do I check the returned value in the XML and throw an
    error if true?
    I appreciate any help with this. Please let me know if there
    is a better way to achieve the same result.
    Thanks,
    Rich

    I enabled the call to the XML response. However, I am having
    trouble identifying when the call is complete so I can parse the
    result. How do I run my check after the data load and display the
    proper message?

  • Help! Need help with preflight package script

    I am trying to write a package with Iceberg to push Office 2004 to 250 Macs. I need a preflight script with a condition that will stop my script if /Applications/Microsoft Office 2004 exists OR if OFFICE 2004 exists. Don't know if searching on the folder name is the best or if there is better way
    If it doesn't exist I want it to continue with with placing Office 2004 in the /Applications folder.
    I don't know how to do conditions (If, then, end)
    PREFLIGHT SCRIPT
    IF /Applications/Microsoft Office 2004 folder exist = STOP
    IF /Applications/Microsoft Office 2004 folder doesn't exist continue with laying down files/folder in the package.
    LAYDOWN FILES
    LAY DOWN FILES IN ICEBERG FILE SECTION OF THE PACKAGE
    POSTFLIGHT SCRIPT
    #!/bin/sh
    #Change to root directory
    cd /
    # Move Microsoft Office X folder to Messages Received folder
    mv /Applications/Microsoft\ Office\ X /Messages\ Received
    #Open Office 2004 Installer
    open /Applications/Utilities/Installers/Office2004Installer
    ALL Mac OS X (10.4.6)
    ALL Mac OS X (10.4.6)
    ALL   Mac OS X (10.4.6)  

    A simple condition (not using iceberg) would be:
    #!/bin/sh
    if [ -e "/Applications/Microsoft Office 2004.app" ]
    then
    echo "Microsoft Office 2004 exists, aborting installation"
    exit 1
    fi
    open -a "/Applications/Utilities/Installers/Office2004Installer"
    If Microsoft Office 2004 is installed then the script will exit with a message. If Microsoft Office 2004 is not there then the last line will be executed and the installer will open.
    PowerBook G4   Mac OS X (10.4.8)   MacBook Pro

  • Help with simple Automator script

    I have a simple Automator script for updating a specified folder with files from another folder. It consists of only two actions:
    1. Get Folder Contents (from the folder I drop on the Automator executable).
    2. Copy Finder Items.
    I left the option "replace existing files" unchecked because there's no point in replacing a bunch of files that already exist (we're talking about 4000-5000 files in the source folder).  I assumed that meant to ignore any existing files but, on the contrary, I found out that the script is copying duplicates of all the existing files -- making my target folder about 9000 files strong!
    How do I get a command into the middle of this script to restrict the Copy Finder Items command to files that do not already exist in the target folder? (It would be even nicer if it could check for files that are older than the files being copied and actually replace (only) those as well.)
    Any ideas?

    If you need the Terminal window to stay open, then you're looking at scripting Terminal. You can do this with Automator's run applescript action, or you can just use Script Editor (in Applications > AppleScript). Either way you will need to save the workflow/script as an application and drag it to your Login Items (in System Preferences > Accounts).
    click here to open this script in your editor<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">tell application "Terminal"
    activate
    set commands to "cd /Users/lenny/ventrilo/ 
    /Users/lenny/ventrilo/ventrilo_srv"
    do script commands in front window
    end tell</pre>
    PowerMac G5 (June 2004) 2x1.8GHz 1.25GB, PowerBook G4 (12-inch DVI) 1x1GHz 768MB   Mac OS X (10.4.3)  

  • Beginner needs help with simple code.

    I just statrted learnind java, and I need some help with this simple program. For some reason everytime I enter my Farenheit value, the Celsius conversion returns as 0.0. Would really appreciate the help. Thanks.
    Here's the code:
    public class TempConverter
    public static void main(String[] args)
    double F = Double.parseDouble(args[0]);
    System.out.println("Temperature in Farenheit is: " + F);
    double C = 5 / 9;
    C *= (F - 32);
    System.out.println("Temperature in Celsius is: " + C);
    }

    double C = 5 / 9This considers "5" and "9" to be integers and does an integer division, discarding the remainder. The result of that division is 0. Trydouble C = 5.0/9.0;

  • Need Help with simple array program!

    Hi, I have just recently started how to use arrays[] in Java and I'm a bit confused and need help designing a program.
    What this program does, it reads in a range of letters specified by the user. The user then enters the letters (a, b or c) and stores these characters into an array, which the array's length is equal to the input range the user would enter at the start of the program. The program is then meant to find how many times (a,b and c) appears in the array and the Index it first appears at, then prints these results.
    Here is my Code for the program, hopefully this would make sense of what my program is suppose to do.
    import B102.*;
    class Letters
         static int GetSize()
              int size = 0;
              boolean err = true;
              while(err == true)
                   Screen.out.println("How Many Letters would you like to read in?");
                   size = Keybd.in.readInt();
                   err = Keybd.in.fail();
                   Keybd.in.clearError();
                   if(size <= 0)
                        err = true;
                        Screen.out.println("Invalid Input");
              return(size);
         static char[] ReadInput(int size)
              char input;
              char[] letter = new char[size];
              for(int start = 1; start <= size; start++)
                   System.out.println("Please enter a letter (a, b or c) ("+size+" max), enter # to stop:");
                   input = Keybd.in.readChar();
                   while((input != 'a') && (input != 'b') && (input != 'c') && (input != '#'))
                        Screen.out.println("Invalid Input");
                        System.out.println("Please enter a letter (a, b or c) ("+size+" max, enter # to stop:");
                        input = Keybd.in.readChar();
                                    while(input == '#')
                                                 start == size;
                                                 break;
                   for(int i = 0; i < letter.length; i++)
                        letter[i] = input;
              return(letter);
         static int CountA(char[] letter)
              int acount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'a')
                        acount++;
              return(acount);
         static int CountB(char[] letter)
              int bcount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'b')
                        bcount++;
              return(bcount);
         static int CountC(char[] letter)
              int ccount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'c')
                        ccount++;
              return(ccount);
         static int SearchA(char[] letter)
              int ia;
              for(ia = 0; ia < letter.length; ia++)
                   if(letter[ia] == 'a')
                        return(ia);
              return(ia);
         static int SearchB(char[] letter)
              int ib;
              for(ib = 0; ib < letter.length; ib++)
                   if(letter[ib] == 'b')
                        return(ib);
              return(ib);
         static int SearchC(char[] letter)
              int ic;
              for(ic = 0; ic < letter.length; ic++)
                   if(letter[ic] == 'c')
                        return(ic);
              return(ic);
         static void PrintResult(char[] letter, int acount, int bcount, int ccount, int ia, int ib, int ic)
              if(ia <= 1)
                   System.out.println("There are "+acount+" a's found, first appearing at index "+ia);
              else
                   System.out.println("There are no a's found");
              if(ib <= 1)
                   System.out.println("There are "+bcount+" b's found, first appearing at index "+ib);
              else
                   System.out.println("There are no b's found");
              if(ic <= 1)
                   System.out.println("There are "+ccount+" c's found, first appearing at index "+ic);
              else
                   System.out.println("There are no c's found");
              return;
         public static void main(String args[])
              int size;
              char[] letter;
              int acount;
              int bcount;
              int ccount;
              int ia;
              int ib;
              int ic;
              size = GetSize();
              letter = ReadInput(size);
              acount = CountA(letter);
              bcount = CountB(letter);
              ccount = CountC(letter);
              ia = SearchA(letter);
              ib = SearchB(letter);
              ic = SearchC(letter);
              PrintResult(letter, acount, bcount, ccount, ia, ib, ic);
              return;
    }     Some errors i get with my program are:
    When reading in the letters to store into the array, I get the last letter I entered placed into the entire array. Also I believe my code to find the Index is incorrect.
    Example Testing: How many letters would you like to read? 3
    Enter letter (a, b or c) (# to quit): a
    Enter letter (a, b or c) (# to quit): b
    Enter letter (a, b or c) (# to quit): c
    It prints "There are no a's'" (there should be 1 a at index 0)
    "There are no b's" (there should be 1 b at index 1)
    and "There are 3 c's, first appearing at index 0" ( there should be 1 c at index 2)
    The last thing is that my code for when the user enters "#" that the input of letters would stop and the program would then continue over to the counting and searching part for the letters, my I believe is correct but I get the same problem as stated above where the program takes the character "#" and stores it into the entire array.
    Example Testing:How many letters would you like to read? 3
    Enter letter (a, b or c) (# to quit): a
    Enter letter (a, b or c) (# to quit): #
    It prints "There are no a's'" (should have been 1 a at index 0)
    "There are no b's"
    and "There are no c's"
    Can someone please help me??? or does anyone have a program simular to this they have done and would'nt mind showing me how it works?
    Thanks
    lou87.

    Without thinking too much...something like this
    for(int start = 0; start < size; start++) {
                System.out.println("Please enter a letter (a, b or c) ("+size+" max), enter # to stop:");
                input = Keybd.in.readChar();
                while((input != 'a') && (input != 'b') && (input != 'c') && (input != '#')) {
                    Screen.out.println("Invalid Input");
                    System.out.println("Please enter a letter (a, b or c) ("+size+" max, enter # to stop:");
                    input = Keybd.in.readChar();
                if(input == '#') {
                        break;
                letter[start] = input;
            }you dont even need to do start = size; coz with the break you go out of the for loop.

  • Need help with Go Pro Hero 3 and Premiere Pro CS6

    Hello,
    I recently acquired PP CS6. I put my clip (30 seconds long) and I go to preview while editing, for the first 1.5 seconds it is fine but then it is very choppy. The audio is fine but the video does not play smoothly. When I save and process the video it is fine. It is frustrating to try to edit video this way. I'm sure I'm missing a step when creating the project but I haven't used Premiere Pro since CS6. This is only happening with Go Pro Hero 3 videos, any of my other cameras are fine. Any ideas? Thanks

    There's a lot of confusion over how video encoding affects subsequent editing performance - a higher data rate has no direct relation to how much effort is required to decode and play the footage, in fact a higher data rate often makes playback easier - which is why transcoding to AVI can help with playback even though the files can be hundreds of times larger. Data rates with the same codec depend on the frame contents and recording quality, but for playback and editing what matters is the GOP (group-of-pictures) structure and the complexity of the encoding algorithm. Provided your disks are fast enough the data rate is immaterial to Premiere.
    With long-GOP files (as typically created by consumer DSLRs and helmet cams) we have keyframes (I-frames) with a complete set of pixel data, then a series of intervening P- and B-frames which only store the difference between 'now' and 'one frame before' or 'one frame after'. Unless you're on an I-frame you have to calculate the chain of differences from the nearest I-frame, and when editing or applying an effect we must  re-calculate the entire GOP, so Premiere has to hold a lot of data in the buffer. Remember all timelines in Premiere are internally transcoded to 32-bit floating point, so it's more work to 'play' the footage in the monitors than would be done by a simple playback-only application such as VLC, or in some other brands of NLE that only work in the footage's color space. Premiere's hardware acceleration (MPE) only kicks in once the buffer has been ingested, all the decoding of the original H.264 frames happens in your CPU.
    With digital cinema cameras and some hacked DSLRs, we record "all-I" footage - so there's no GOP overhead and playback/editing is massively smoother. I can scrub all-I footage from a hacked 7D no problem on my relatively-ancient spare laptop, but the  long-GOP files from a factory 7D struggle to play at all. Our all-I 7D footage can hit 300MBit/s compared to 35 for long-GOP. Helmet cams such as the GoPro do all they possibly can to squeeze data onto their storage cards, which means they have long-GOP codecs that have some of the most complicated compression algorithms out there. The Hero3's implementation of H.264 uses the Ambarella chip, whose files are very small but an utter nightmare to decode - hence far more of a demand on your CPU than an equivalent clip from a DSLR.
    Jim Simon wrote:
    Might be the 35 Mbps that is causing the choppy playback.
    It shouldn't, assuming sufficient hardware.  My GH2 clips often get up to over 90 Mb/s and play just fine on an older i7 920.

  • HT4061 I need help with my I-phone 4S and the Cloud,  I can't locate my serial number  I also have a new 4g I-Pad  Can someone help me

    I need help to locate my pictures in the cloud
    When my son updated my phone early this year it wiped out all my pictues on my I-phone 4S
    How do I access the cloud to view my pictures??

    Do you have Photo Stream enabled with your iCloud account on your computer?
    iCloud is temporary storage - limited to 1,000 photos and 30 days for each photo.
    Photos/videos in your iPhone's Camera Roll can and should be imported by your computer as with any other digital camera especially before installing an iOS update.

  • I need help with simple problems. im a student.

    i'd like to be advanced with my studies so i will post questions.. i need help on how to answer. thank you.
    1. create a java program that will evaluate if the value entered is a positive, negative, vowel, consonant and special characters.
    im actually done with the positive and negative using if else statements.. i used an integer data type. now my question is how do conjoin the characters when i need to evaluate a vowel and a consonant. i cant use char either. please help. i dont know what to do yet.
    2. create java program that will translate the input from numbers to words. e.g. input:123 output: one hundred twenty-three.
    i have an idea to use a switch case statement. but i have no idea on how will i be able to do it. so if you guys can help me.. well then thankies..

    Welcome to the Sun forums. First, please note that you have posted in the wrong forum. This forum is for topics related to Sun's JavaHelp product. You should post your questions in the New to Java forum.
    As part of your learning, you will have to develop the ability to select an approach to a problem, create a design that reflects that approach, and then implement the design with code that you create.
    So, it's inappropriate for us to take the problem statement that you have been given and short-circuit your learning process by giving you the implemented problem solution. We can comment on the individual questions that you may have, and point out problems and errors that we see in the code that you develop.
    As a hint, when you are stuck, forget about Java and programming. Just start with a sheet of paper and a pencil, and figure out how to layout the task on paper. The consider how to translate that to programming.
    If you have problems, post short example code that shows the problem, and explain your question clearly. We can't read minds.
    Make sure you post code correctly so that it's not mangled by the forum software, and so that formatting is maintained. Select your typed or pasted code block and press the CODE button above the typing area.

  • Need help with Color Profiles between Photoshop and iPhoto

    Hey guys, I'm a photographer and have always used Photoshop in comination with iPhoto. I am having great difficulty lately with color profiles randomly changing within albums of pictures. I need all of my images to be in sRGB, but some somehow end up in Adobe RGB. It seems to happen at random. Apple seems to think it's an Adobe problem. Adobe isn't sure what to do. Anybody aware of any known issues between CS5 and iPhoto using OS 10.8.4 with regard to color profiles and how to fix them?

    SRiegel schrieb:
    I don't know inkscape, but this article seems to indicate that is will support cmyk.
    The article also says you need Scribus to then further process the SVG file.
    @shaunamm You need to open the SVGin Illustrator, not place it. But I doubt that you will be able to get the effects in Illustrator.

Maybe you are looking for