Help with Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fernando Armenta

    Help with Python

    Hello!



    I am new to Python and I would like to write the following code:



    I need to check for a directory and move it to other directory if is
    found. The directory always starts with outlog.XYZ and ends in XYZ
    (where XYZ are variables). I need to use wild characters. Here is what
    I have, but is not working. Any help would be appreciated.



    #Path for the file

    home_trace = "/home/testeng/ca/tds/outlog.* "



    #Path for the directory where I want to move the file

    directory = "/home/testeng/ca/tds/unattached"



    #If statement

    if os.path.exists( home_trace):

    os.system ("chmod -fR 775 outlog.* ")

    os.system ("mv outlog.* " + directory)



    Fernando Armenta




  • Christos TZOTZIOY Georgiou

    #2
    Re: Help with Python

    On Tue, 16 Sep 2003 14:16:56 -0700, rumours say that "Fernando Armenta"
    <farmenta@pilla rdata.com> might have written:
    [color=blue]
    >I need to check for a directory and move it to other directory if is
    >found. The directory always starts with outlog.XYZ and ends in XYZ
    >(where XYZ are variables). I need to use wild characters. Here is what
    >I have, but is not working. Any help would be appreciated.
    >
    >
    >
    >#Path for the file
    >
    >home_trace = "/home/testeng/ca/tds/outlog.* "
    >
    >
    >
    >#Path for the directory where I want to move the file
    >
    >directory = "/home/testeng/ca/tds/unattached"
    >
    >
    >
    >#If statement
    >
    >if os.path.exists( home_trace):
    >
    > os.system ("chmod -fR 775 outlog.* ")
    >
    > os.system ("mv outlog.* " + directory)[/color]

    Import glob, then for each file in glob.glob('outl og.*'), use os.chmod()
    and os.rename() with appropriate parameters. os.rename() would probably
    fail if you moved your files to another filesystem, but in your example
    this does not seem to be the case.

    PS I just remembered that I have seen at least one C++ freshly-graduated
    programmer serving as a sysadm in a university praising C++ as a
    scripting language (!); his code was full of system() calls. When I
    asked him, "why not a shell script?", he said "this is faster... it's
    C++...".
    I mentioned the difference of a shell doing spawn() and an executable
    doing spawn() to a shell doing another spawn().
    Discussing it further, he said that executables are not "legible"; so,
    *just before* suggesting a "chmod 500" operation on a root-owned script,
    I told him about the "strings" command as an obvious counter-argument
    for a naive disassembly. I chose the wrong order of sentences; he
    actually removed /usr/bin/strings in haste, as if his job was depending
    on its disappearance.. . FWIW, it did --in the opposite way.
    There are no limits.
    --
    TZOTZIOY, I speak England very best,
    Microsoft Security Alert: the Matrix began as open source.

    Comment

    Working...