Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 13:31, 31 March 2008.

How to use easily files and directories

From Forum Nokia Wiki


With third party modules

The original path module is not easy to use. It's difficult to remember how to use it. But pypath from Jasen Orenberg could be a good replacement for it. So this module has been adapted to Python S60.

Here's an example code snippet for erasing all compiled files in python folder :

# with pypath
 
d = path('c:\\python')
for f in d.walkfiles('*.pyc'):
    f.remove()


With built-in methods

To see a list of files in a directory using the default modules and methods, we do something like this:

import os, codecs
 
folder="C:\\Python"
for f in os.listdir(folder):
    print f
    #Or, we can also see which files have a certain beginning or end:
    if(f.startswith('a')):print f
    if(f.endswith('.mp3')):print f


To get the list of available drives:

from e32 import *
 
print drive_list()   #Returns a list of the drives as unicode, [u'C:', u'D:', u'E:', u'Z:']


To copy a file, the function file_copy(target_name, source_name) is used, where the names must be full paths. For example:

from e32 import *
 
file_copy("C:\\Data\\file.txt","E:\\file.txt")


!!Renaming or deleting some files and/or folders may make the device unstable. Use these functions with care.


To delete a file we use the remove(path) function.

import os
 
os.remove("C:\\Python\\ball.py")


To rename a file or directory:

import os
 
os.rename("C:\\Python\\ball.py", "C:\\Python\\roundObject.py")
os.rename("C:\\Data\\Images", "C:\\Data\\Graphics")


To create a folder:

import os
 
os.mkdir("C:\\Myfolder")


To delete a folder:

import os
 
os.rmdir("C:\\Myfolder")
Related Discussions
Thread Thread Starter Forum Replies Last Post
文件不存在就创建然后写,存在就打开写,怎么做啊 Chenqs2100 Symbian 7 2006-03-28 02:47
EPOC emulator structure documentation (S60, 3rd Ed) sysctl Symbian Tools & SDKs 2 2006-12-26 14:52
Directories mixup nightmare SIBUK General Symbian C++ 2 2006-04-05 07:26
Carbide C++ compiles C files as C++? metalim Carbide.c++ and CodeWarrior Tools 2 2007-01-21 17:41
Steps to create new project with VC++ 6 rammstein.ie General Symbian C++ 3 2003-09-09 00:02
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZpythonQ
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX