i know how to open a file and access its elements..now i have to open a folder containing these files and work with these files..
the normal open("directoryname") is giving me an error.
any suggestions??
looking for ur reply!
cheers!
7 27540
i know how to open a file and access its elements..now i have to open a folder containing these files and work with these files..
the normal open("directoryname") is giving me an error.
any suggestions??
looking for ur reply!
cheers!
check out os.listdir() or os.walk().
check out os.listdir() or os.walk().
i kind of tried checking how this command really works in google i could not really understand.
what i typically want to do is th
file=open("filename","r")
instead of this i want to open the directory containing these files.
file=open("directoryname","r")
when i use -
import os
-
seq=os.listdir(directory name")
-
doesnt seem to work
waiting for ur reply,
cheers!
i kind of tried checking how this command really works in google i could not really understand.
what i typically want to do is th
file=open("filename","r")
instead of this i want to open the directory containing these files.
file=open("directoryname","r")
when i use -
import os
-
seq=os.listdir(directory name")
-
doesnt seem to work
waiting for ur reply,
cheers!
what doesn't seem to work? did you print out the seq variable and see if there's any values? -
seq = os.listdir("directory")
-
print seq
-
-
bvdet 2,851
Expert Mod 2GB
i kind of tried checking how this command really works in google i could not really understand.
what i typically want to do is th
file=open("filename","r")
instead of this i want to open the directory containing these files.
file=open("directoryname","r")
when i use -
import os
-
seq=os.listdir(directory name")
-
doesnt seem to work
waiting for ur reply,
cheers!
You cannot open a directory with the built-in function file(). You can create a filtered list of files found in a specific directory with the os module. - >>> import os
-
# Create a list of directory entries
-
>>> dir_name = 'X:\\TEMP\\temp'
-
>>> fList = os.listdir(dir_name)
-
# The directory entries do not include the full path
-
# Create a list of file names with full path, eliminating subdirectory entries
-
>>> fList1 = [os.path.join(dir_name, f) for f in fList if os.path.isfile(os.path.join(dir_name, f))]
Alternatively, you can change your current working directory with os.chdir() and you will not need the full path to access the files.
okay, that kind of works.that lists the file which i can handle
but to get into the files..this is what am trying -
import os
-
seq=os.listdir("ding")
-
print seq
-
# this lists all the file
-
for i,rem in enumerate(seqq):
-
rem=open("i","r")
-
print rem
-
-
this does not seem to work.
waiting for reply,
cheers!
bvdet 2,851
Expert Mod 2GB
okay, that kind of works.that lists the file which i can handle
but to get into the files..this is what am trying -
import os
-
seq=os.listdir("ding")
-
print seq
-
# this lists all the file
-
for i,rem in enumerate(seqq):
-
rem=open("i","r")
-
print rem
-
-
this does not seem to work.
waiting for reply,
cheers!
Try this (untested): - import os
-
seq=os.listdir("ding")
-
print seq
-
os.chdir("ding")
-
for f in seq:
-
if os.path.isfile(f):
-
rem = open("f")
-
print rem.read()
-
rem.close()
thanks a lot..that helped!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Etienne Charland |
last post by:
Hi, I have a solution containing 6 C# projects; 1 WinForms project and 5
class libraries. I didn't have any problems until recently. I added a new
project containing reports. I am using...
|
by: KevinGravelle |
last post by:
Hello,
I am running an Apache web server and my httpd configuration file is
utilizing the aspdotnet_module in order to run an ASP.NET application.
Whenever I try and open my existing web...
|
by: Hemant Shah |
last post by:
Folks,
I need to move HOME directory of an instance to another directory.
What is the best way of doing it?
Is changing password file enough? or dies DB2 store this info in it's own
config?
...
|
by: Mink |
last post by:
I have a code that checks a directory to see if it exists, and then if
it does not, the code creates the directory and allows the user to
add/view files in the directory. Weekly I print a report...
|
by: Kenneth P |
last post by:
Hi,
I've had a hd crash (with proper data backup) and I wonder what way would be
the best way to set up an old project with all code from a backup hd in a new
vs.net2003 environment?
TIA
...
|
by: Brad Wood |
last post by:
I've reinstalled my operating system and now want to reopen a web
service project.
Here is the URLPath in my project's .webinfo file:
"http://localhost/DriverService/DriverWebService.csproj"
...
|
by: comp.lang.php |
last post by:
Once again, I thought my class method deleteZip() would do the trick,
but it never deletes any .zip* file found in a directory:
/**
* Delete any latent ZIP files found in this album. This...
|
by: MoshiachNow |
last post by:
HI,
I try to open a link using %windir% in path:
<LI><A HREF="%windir%/temp/MainSetupLog.log">F </A></LI>
The browser does not seem to find the file.
However,If I paste in the Address window:...
|
by: nickvans |
last post by:
Hi all,
I have a database which is used to narrow down and select part drawings. The drawings are stored as .jpg files. I have a table relating the the part number to the file containing the...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |