Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Korakot Chaovavanich http://korakot.stumbleupon.com

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Manipulate files and directory easily with path.py (on pys60)

I really like Jason Orendorff's path.py.
So, I modify it a bit to use with pys60.
- don't load fnmatch, glob, codecs
- remove some functionalities and some docstrings
- match wildcard with regexp simplisticly
   1  
   2  #return fnmatch.fnmatch(self.name, pattern)
   3  
   4  # poor man's fnmatch
   5  pattern = pattern.replace('.', '\\.').replace('*','.*').replace('?','.')
   6  return re.match(pattern, self.name)

But most of it works nicely. Please report bugs in comments.
Download it here path.py.

Common directory tasks

   1  
   2  >>> import os
   3  >>> os.getcwd()
   4  'C:\\lang\\python23'
   5  >>> os.listdir('C:/lang')
   6  ['editplus', 'python23', 'perl', 'ironpy', 'java142', 'processing']
   7  >>> os.chdir('C:/')
   8  >>>

This is eqivalent to common task on command line
- Show current directory
- List content in a directory
- Change directory

common command line equivalent in python

>>> import os

>>> os.getcwd() # get current working directory
'C:\\lang\\python23'

>>> os.chdir('C:/') # change directory
>>> os.chdir('lang') # again

>>> os.listdir('.') # list
['dotnet', 'try', 'editplus', 'python23', 'leo', 'mingw', 'perl', 'gtk', 'ironpy', 'java142']
>>>
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS