[Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
Hello,

This is my first post. I have just begun to code with python. My goal is to 
convert about a dozen or 
so DOS/Windows batch scripts(.bat) and vbscripts(.vbs) that I use on a 
day-to-day basis to python so 
that they can be run on either my windows or linux workstations.

The first things that I want to learn is how to do basic stuff like copying, 
moving, and deleting 
files around from folder to folder. I have been in the help section of python 
(copyfile section) 
but I do not understand what I am doing wrong.


Here is my simple DOS batch file...

##
copy D:\PDF_Holding\*PRODUCTION.pdf Z:\
copy D:\PDF_Holding\*ILLUSTRATION.pdf H:\MARKETING\ILLUSTRATIONS\PRODUCT
pause

del *.pdf
##

Basically, it copies the "production" and "illustration" pdf files to certain 
folders than deletes 
the left over pdf files when done. Yes, I could move them instead of copying 
them.

I'm no asking for anyone to write this for me but if someone could lead me i 
the right direction, I 
would be grateful.

Thank-you.

Mark
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
Wow! Got a lot of responses to my post. Thanks everyone. After reading all of 
them, I may have to 
learn by example after all.  I'm going to try Alan Gauld's tutorials first.

Mark

Alan Gauld wrote the following on 2/15/2007 12:39 PM:
> "Mark Bystry" <[EMAIL PROTECTED]> wrote
> 
>> My goal is to convert about a dozen or so DOS/Windows batch 
>> scripts(.bat) and vbscripts(.vbs) that I use on a day-to-day basis 
>> to python 
> 
> You might want to look at my Using the OS topic in my tutorial
> It covers basic file manipulation and starting external programs 
> etc.
> 
>> that they can be run on either my windows or linux workstations.
> 
> That might be harder than you think due to differences in paths etc.
> Also some external commands will be different, and ones with the 
> same name take different arguments/orders or args etc
> 
> If you write them in pure Python you should be OK but if you 
> just run sequences of OS commands (typical of batch files) 
> then you might run into problems.
> 
>> The first things that I want to learn is how to do basic stuff 
>> like copying, moving, and deleting files around from folder to 
>> folder. 
> 
> Try my tutor topic.
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
You guys are great! I'm not sure how I found this mailing list but I'm glad 
that I subscribed.

Mark

Rob Andrews wrote the following on 2/15/2007 1:23 PM:
> We're good like that. heh
> 
> On 2/15/07, Mark Bystry <[EMAIL PROTECTED]> wrote:
>> Wow! Got a lot of responses to my post. Thanks everyone. After reading all 
>> of them, I may have to
>> learn by example after all.  I'm going to try Alan Gauld's tutorials first.
>>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
Well, immediately I am having problems. Be patient with me.

This what I have...

copy_file.py


import os
import shutil as sh

sh.copy('C:\testing_it.txt', 'D:\')
raw_input("Done!")



...and it's not working. Obviously, I'm trying to copy a text file on C:\ to 
D:\.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
Jeez! I'm retarded. It works like a charm now.

Thanks for that Rob

Mark

Rob Andrews wrote the following on 2/15/2007 2:29 PM:
> Ahh, yes. Your main trouble seems to be the use of \ instead of / in
> 'C:\testing_it.txt'
> 
> Windows uses \, whereas python uses /. So you can replace 'c:\'
> with your choice of the following:
> 
> 'c:/' (replacing \ with /)
> r'c:\' (the 'r' before the string tells python it's a raw string)
> 'c:\\' (the first \ telling python to take the second \ at face value)
> 
> -Rob A.
> 
> On 2/15/07, Mark Bystry <[EMAIL PROTECTED]> wrote:
>> Well, immediately I am having problems. Be patient with me.
>>
>> This what I have...
>>
>> copy_file.py
>> 
>>
>> import os
>> import shutil as sh
>>
>> sh.copy('C:\testing_it.txt', 'D:\')
>> raw_input("Done!")
>>
>> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Convert my .bat and .vbs to .py

2007-02-15 Thread Mark Bystry
Ahh. Great tip Eric. Thank-you.

Mark


Eric Walstad wrote the following on 2/15/2007 2:58 PM:
> Hey Mark,
> Mark Bystry wrote:
>> sh.copy('C:\testing_it.txt', 'D:\')
> 
> Also have a look at the os.path module.  Because you want these scripts
> to work on both Linux and Windows, using os.path will let you avoid
> writing platform specific code to handle your slashes.
> 
> For example:
> import os
> path_parts_list = ['C:', 'testing_it.txt']
> 
> Now, os.path.join will join those path parts together with whatever is
> appropriate for the OS you are running on:
> 
> os.path.join(path_parts_list)
> 
> This should give you:
> 'c:\testing_it.txt' on Windows and
> 'c:/testing_it.txt' on Linux (which doesn't make sense, but demonstrates
> how os.path can handle your os-specific slashes for you).
> 
> There are lots of helpful path related built-ins:
> <http://docs.python.org/lib/module-os.path.html>
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New Tutor topic(almost)

2007-02-16 Thread Mark Bystry
Well, I'm new here and for the most I haven't got a clue as to what I'm doing, 
however, I thought 
your website was a jewel. Most of it was over my head but sometime in the 
future I'm sure it will 
become a valuable resource for me. (btw, I'm heading to Borders tonight with my 
checkbook. Hoping to 
pick up some pyhton for complete n00bs reading)

Keep up the great work, Alan.

Mark

Alan Gauld wrote the following on 2/16/2007 4:45 AM:
> "Alan Gauld" <[EMAIL PROTECTED]> wrote in 
> 
>> After a very long delay I finally got some work done on 
>> my networking with sockets topic in my tutorial. There is 
>> still a section to complete but the introductory explanations 
>> and examples are now on the site.
>>
>> http://www.freenetpages.co.uk/hp/alan.gauld/tutsocket.htm
>>
>> If anyone has any feedback I'd love to hear it.
> 
> OK, I finished it, the final address book example is now there too.
> 
> Enjoy,
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New Tutor topic(almost)

2007-02-16 Thread Mark Bystry
I'll look for it. Perhaps I should pick up one of the "Dummies" book too.

Mark

Kent Johnson wrote the following on 2/16/2007 8:35 AM:
> Mark Bystry wrote:
>> Well, I'm new here and for the most I haven't got a clue as to what I'm 
>> doing, however, I thought 
>> your website was a jewel. Most of it was over my head but sometime in the 
>> future I'm sure it will 
>> become a valuable resource for me. (btw, I'm heading to Borders tonight with 
>> my checkbook. Hoping to 
>> pick up some pyhton for complete n00bs reading)
> 
> Look for "Python Programming for the absolute beginner".
> 
> Kent
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Add metadata to a dir of files.

2007-02-22 Thread Mark Bystry
Ok. I'm not sure what programming language I want to try this in...since I'm 
not sure how to write 
this in any language (thought I'd give python a try.

Here's my problem: I have a directory full of about 2,000 pdf files. I want to 
be able to add the 
same comment to the "Category" field of each file (in the document properties 
of the file). So I am 
looking to batch process pdf files (or any filetype, i guess) to add some 
metadata.

My needs are very similar to tagging mp3 files.

Since I'm still new to python I don't even know how to get started. Can someone 
provide sample code 
that maybe I could expand upon or point to a link somewhere so I can read up on 
the subject?

I would appreciate it.

Thank-you,

Mark
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Add metadata to a dir of files.

2007-02-22 Thread Mark Bystry
Actually no. I want to change the Windows metadata. This is the same metadata 
that is on all files. 
It isn't PDF specific. (I wonder if Linux is the same)

Basically, I can select 100's of file in a dir, right-click, properties, 
summary, and add something 
to the Category field. This obviously affects all files giving them all the 
same attribute. I can 
continue doing it this way but I thought perhaps a script would be best. Maybe 
it isn't, I don't know.

Anyway, thank-you for the links.

Mark

Tim Golden wrote the following on 2/22/2007 12:28 PM:
>> Here's my problem: I have a directory full of about 2,000 pdf files. I want 
>> to be able to add the 
>> same comment to the "Category" field of each file (in the document 
>> properties of the file). So I am 
>> looking to batch process pdf files (or any filetype, i guess) to add some 
>> metadata.
> 
> I'm assuming here that we're talking about the PDF's
> own metadata rather than, say, the additional stuff
> which Windows allows in Alternate Data Streams? If
> so, then a combination of PyPDF:
> 
>http://pybrary.net/pyPdf/
> 
> and the builtin os, glob, os.path modules:
> 
>http://docs.python.org/lib/module-os.html
>http://docs.python.org/lib/module-os.path.html
>http://docs.python.org/lib/module-glob.html
> 
> might suit the case.
> 
> TJG
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Add metadata to a dir of files.

2007-02-22 Thread Mark Bystry
I think I'm getting close but with the wrong programming language...

filename: test.vbs
code:
Set objFile = CreateObject("DSOFile.OleDocumentProperties")
objFile.Open("C:\test.txt")
Wscript.Echo "Category: " & objFile.SummaryProperties.Category

With the help of dsofile.dll the above reads the "Category" attribute of 
test.txt.


Mark Bystry wrote the following on 2/22/2007 1:01 PM:
> Actually no. I want to change the Windows metadata. This is the same metadata 
> that is on all files. 
> It isn't PDF specific. (I wonder if Linux is the same)
> 
> Basically, I can select 100's of file in a dir, right-click, properties, 
> summary, and add something 
> to the Category field. This obviously affects all files giving them all the 
> same attribute. I can 
> continue doing it this way but I thought perhaps a script would be best. 
> Maybe it isn't, I don't know.
> 
> Anyway, thank-you for the links.
> 
> Mark
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Add metadata to a dir of files.

2007-02-22 Thread Mark Bystry
getting even closer. figure out how to write to a file but still in vbscript.

dsofile_write.vbs
code:
Set objFile = CreateObject("DSOFile.OleDocumentProperties")
objFile.Open("D:\test.txt")
objFile.SummaryProperties.Category = "CAT54"
objFile.Save

Mark

Mark Bystry wrote the following on 2/22/2007 1:30 PM:
> I think I'm getting close but with the wrong programming language...
> 
> filename: test.vbs
> code:
> Set objFile = CreateObject("DSOFile.OleDocumentProperties")
> objFile.Open("C:\test.txt")
> Wscript.Echo "Category: " & objFile.SummaryProperties.Category
> 
> With the help of dsofile.dll the above reads the "Category" attribute of 
> test.txt.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Add metadata to a dir of files.

2007-02-22 Thread Mark Bystry
Well that's awesome. Thanks for the code. Unfortunately I cannot get it to run. 
After I installed 
the win32 extensions for python...I get this error when trying to run.

Traceback (most recent call last):
   File "C:\test.py", line 4, in 
 props.SummaryProperties.Category = "CAT69"
   File "C:\Program 
Files\Python25\Lib\site-packages\win32com\client\dynamic.py", line 534, in 
__setattr__
 self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, 
-2147024891), None)

code:
import win32com.client
props = win32com.client.Dispatch ("DSOFile.OleDocumentProperties")
props.Open (r"C:\test.txt")
props.SummaryProperties.Category = "CAT69"
props.Save ()


Maybe this is the same com error that you're getting

Mark


Tim Golden wrote the following on 2/22/2007 3:16 PM:
> Mark Bystry wrote:
>> getting even closer. figure out how to write to a file but still in vbscript.
>>
>> dsofile_write.vbs
>> code:
>> Set objFile = CreateObject("DSOFile.OleDocumentProperties")
>> objFile.Open("D:\test.txt")
>> objFile.SummaryProperties.Category = "CAT54"
>> objFile.Save
> 
> In Python, that's spelt:
> 
> 
> import win32com.client
> props = win32com.client.Dispatch ("DSOFile.OleDocumentProperties")
> props.Open (r"c:\temp\test.txt")
> props.SummaryProperties.Category = "CAT54"
> props.Save ()
> 
> 
> 
> but when I tried doing it, I got a COM error on the line
> where the Category is written. It worked ok with Subject
> instead. Wouldn't have thought this was down to Python,
> but I've not got much to go on!
> 
> TJG
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Add metadata to a dir of files.

2007-02-23 Thread Mark Bystry
Ok, Tim. I believe you're right. If the vbscript is working then I'll continue 
to use it and expand 
on it. I'll only be using this on my WinXP box anyway. I just didn't want to 
offend anyone in this 
mailing list with vbscript code. I'm really trying to learn some python basics 
but I'm no programmer.

Thanks everyone for your help.

Mark.

Tim Golden wrote the following on 2/22/2007 4:06 PM:
> Tim Golden wrote:
>> Slightly bizarrely, it works fine for me on a different
>> computer (my laptop). Both are Win2K. The only help I
>> could find on the error code suggested a permission issue,
>> which isn't likely. That said, I have experienced a few
>> funnies with the Python script writing the new Category
>> open in one window, and trying to use Explorer to update
>> the Summary info in another.
>>
>> Might be worth making sure nothing else is blocking, and
>> giving it another go. I'll try it on a random collection
>> of files to see if it runs...
> 
> No joy. It's falling over again with another eight-byte
> twos-complement error code. Frankly, if your VBS version
> runs, use it! (Especially if this is just one of those
> one-off things).
> 
> TJG
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor