Help with Python

F

Fernando Armenta

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
 
C

Christos TZOTZIOY Georgiou

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)

Import glob, then for each file in glob.glob('outlog.*'), 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top