473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Re: recursive using the os.walk(path) from the os module

A. Joseph wrote:
I want to search through a directory and re-arrange all the files into e.g

All .doc files go into MS WORD folder, all .pdf files goes into PDF Folder.

I`m thinking of doing something with the os.walk(path) method from os
module, I need some ideal how the algorithm should look like, maybe
recursive ..any deal?
os.walk traverses the directory tree, so I'm not sure why you think that
your program needs to use recursion? wouldn't a plain loop work?

import os, shutil

for dirpath, dirnames, filenames in os.walk(directory):
for name in filenames:
source = os.path.join(dirpath, name)
... check extension and determine target directory ...
destination = os.path.join(targetdir, name)
shutil.move(source, destination)

tweak as necessary.

</F>

Sep 17 '08 #1
0 1526

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

Similar topics

9
by: Bryan | last post by:
i have a batch file that contains these two lines: -- args.bat echo %1 echo %2 when i run args.bat from the command line it works correctly... notice that abc has quotes in the first...
15
by: TaeKyon | last post by:
I'm a python newbie; here are a few questions relative to a problem I'm trying to solve; I'm wandering if python is the best instrument or if awk or a mix of bash and sed would be better: 1) how...
3
by: rbt | last post by:
I'm trying to write very small, modular code as functions to break up a big monolithic script that does a file system search for particular strings. The script works well, but it's not easy to...
6
by: rtilley | last post by:
Hello, When working with file and dir info recursively on Windows XP. I'm going about it like this: for root, dirs, files in os.walk(path): for f in files: ADD F to dictionary for d in...
2
by: WestAussie | last post by:
Hello This is my first attempt at using VB .NET, and I'm having some trouble identifying the correct means by which to access a form using a procedure stored within a module. I've been using VBA...
2
by: Martin Marcher | last post by:
Hello, I'm playing around with os.walk and I made up del_tree(path) which I think is correct (in terms of the algorithm, but not as python wants it :)). As soon as some directory is deleted...
12
by: Lance Wynn | last post by:
Hello all, Is there a way to use the ~/ path to link a CSS page? I thought maybe something like this would work, but no go: <link href="~/style.css" rel="stylesheet" type="text/css"/> Is this...
17
by: madasamonkey | last post by:
If someone could take pity and help me out with this before I drive myself completely nuts, then I would really appreciate it. Here's what I'm trying to do: I have an Access 2003 database...
0
by: Simon Brunning | last post by:
2008/9/17 A. Joseph <joefazee@gmail.com>: This help? http://code.activestate.com/recipes/499305/ -- Cheers, Simon B. simon@brunningonline.net
0
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...
0
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...
0
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
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
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...
0
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...
0
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...

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.