473,809 Members | 2,804 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dealing with paths (Unix question)

hey there all!
i'm writing some little programs, and i'd like to know about how to deal
with directories on unix. i've read up on this, but the docs don't really
mention much on it. do i use the pickle module, or something?

what i'd like to do is read in a path, say
/home/username/images/
and that path contains a dir called downloads and some png files,
and it also contains another dir called icons, which holds jpg, png and
gif files.
Now, is it posible to go through that top directory and recursively go
through /icons/ and /downloads/ and pick out all files of a certain
extension(only png files, for example)?

something like:
for each_file in /home/username/images:
if image_extension is png:
add image path to list
but as i said, i need something to work recursively though an arbitrary
number of directories.

sorry if i wan't too clear here :/
if anyone can post some clues on the modules/methods i'd use, and maybe
some example code, that'll be *very* much appreciated!

thanks for reading.
paul.
Jul 18 '05 #1
4 1688
On Sun, 03 Aug 2003 03:04:13 +0000, paul wrote:
hey there all!
i'm writing some little programs, and i'd like to know about how to deal
with directories on unix. i've read up on this, but the docs don't really
mention much on it. do i use the pickle module, or something?


Look at os.path.walk
--
Visit my blog - http://blog.scalegen.com
Music, Programming, and More.

Jul 18 '05 #2
Or os.walk, that might be easier for a beginner. I think that's new though
in 2.3.

"Tyler Eaves" <ty***@scalegen .com> wrote in message
news:pa******** *************** *****@scalegen. com...
On Sun, 03 Aug 2003 03:04:13 +0000, paul wrote:
hey there all!
i'm writing some little programs, and i'd like to know about how to deal
with directories on unix. i've read up on this, but the docs don't really mention much on it. do i use the pickle module, or something?


Look at os.path.walk
--
Visit my blog - http://blog.scalegen.com
Music, Programming, and More.

Jul 18 '05 #3
On Sun, 03 Aug 2003 03:04:13 +0000, paul wrote:
hey there all!

<snip>

cheers for the replies Tyler, Bjorn and Andy. I'll be checking out
os.path, etc...

fun fun fun...
paul.

Jul 18 '05 #4
paul <ap************ ********@breath e.com> wrote in message news:<pa******* *************** *****@breathe.c om>...
hey there all!
i'm writing some little programs, and i'd like to know about how to deal
with directories on unix. i've read up on this, but the docs don't really
mention much on it. do i use the pickle module, or something?

what i'd like to do is read in a path, say
/home/username/images/
and that path contains a dir called downloads and some png files,
and it also contains another dir called icons, which holds jpg, png and
gif files.
Now, is it posible to go through that top directory and recursively go
through /icons/ and /downloads/ and pick out all files of a certain
extension(only png files, for example)?

something like:
for each_file in /home/username/images:
if image_extension is png:
add image path to list
but as i said, i need something to work recursively though an arbitrary
number of directories.

sorry if i wan't too clear here :/
if anyone can post some clues on the modules/methods i'd use, and maybe
some example code, that'll be *very* much appreciated!

thanks for reading.
paul.


You may also want to look at this recipe:

http://aspn.activestate.com/ASPN/Coo.../Recipe/212959

M.S.
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
18129
by: Noah | last post by:
Does anyone have a function to convert back and forth between NT style paths and POSIX style? It seems trivial, but I want to make sure I don't overlook some obscure detail. Is it a simple matter of translating / and \ characters? FYI, I need a Python function that does what cygpath does so that I can run a script on either NT or UNIX or Cygwin. I want my config files use one style of path. Yours,
11
3661
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own rules when it comes to file paths. A lot of Microsoft installers for example, and also installers of other companies, do not work because they handle paths in the following manner:
1
2089
by: vck_82 | last post by:
HI Does any body know how to convert windows style path to posix style path. I need this because i am developing a windows application which actually starts an exe which is developed in unix. The exe only supports unix style of paths. So, i need to convert the path before sending the path to the exe. please help me if anybody know about it. thanks and regards
5
4937
by: Shane Thomas | last post by:
Hello, I'm having difficulty handling cookies with paths other than "/". An HttpWebRequest object returns these headers: Date: Tue, 26 Apr 2005 21:29:39 GMT Server: Apache/1.3.33 (Unix) PHP/4.3.10 Set-cookie: phpusid=12345; path=/; expires=Wednesday, 09-Nov-2008 23:12:40 GMT,data=deleted; expires=Mon, 26-Apr-2004 21:29:38 GMT; path=/stats; domain=www.somesite.com,data=deleted; expires=Mon, 26-Apr-2004 21:29:38 GMT;
3
2615
by: dkacher | last post by:
Hi - I'm looking for a way to generate a list of the fully-qualified paths to all of the leaf nodes in an XML Schema. The reason: I have a large schema for which I'm building a transform stylesheet; I need to be sure I've covered everything. With a list of the paths to all the leaves, I can check off my progress. Have you encountered a program that can generate such a list? Or any pointers about how to approach it? It seems that there...
3
1406
by: Jeff | last post by:
I don't have much knowledge of javascript, but need to place a very small amount in a web page. I figured out everything other than how to properly call a page in another folder/directory. Apparently javascript doesn't like some of the dos and unix conventions with which I'm familiar. Could someone tell me now to properly specify a path name in javascript (i.e., how to refer to a page that is in the parent folder similar to below, which...
3
2852
by: Pat | last post by:
Hi - We're trying to set up an HADR pair on two databases on instances with different names on separate servers. The databases were defined as follows: CREATE DATABASE database1 ON '/db2home/instanceA'; CREATE DATABASE database2 ON '/db2home/instanceB';
6
3180
by: Jon Slaughter | last post by:
do I have to prefix every absolute path with document root to get it to work? For some reason I thought that prefixing a path with '/' or './' with make it absolute w.r.t to document root but I guess not? e.g., when I do include './Scripts/AddNav.php';
5
1589
by: antar2 | last post by:
Hello, I would like to read and print files, of which the complete filepaths are mentioned in another textfile. In this textfile (list.txt) are for example the following paths: /data/chorec/chorec-nieuw/s01/S01C001M1/S01C001M1_1LG_f01.TextGrid /data/chorec/chorec-nieuw/s01/S01C001M1/ S01C001M1_1LGPseudo_f01.TextGrid
0
9603
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10391
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10121
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.