Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6854245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:36:35+00:00 2026-05-27T01:36:35+00:00

Im rather new to python but I have been attemping to learn the basics.

  • 0

Im rather new to python but I have been attemping to learn the basics.

Anyways I have several files that once i have extracted from their zip files (painfully slow process btw) produce several hundred subdirectories with 2-3 files in each. Now what I want to do is extract all those files ending with ‘dem.tif’ and place them in a seperate file (move not copy).

I may have attempted to jump into the deep end here but the code i’ve written runs without error so it must not be finding the files (that do exist!) as it gives me the else statement. Here is the code i’ve created

import os

src = 'O:\DATA\ASTER GDEM\Original\North America\UTM Zone 14\USA\Extracted' # input
dst = 'O:\DATA\ASTER GDEM\Original\North America\UTM Zone 14\USA\Analyses' # desired     location

def move():
    for (dirpath, dirs, files) in os.walk(src):
        if files.endswith('dem.tif'):
            shutil.move(os.path.join(src,files),dst)
            print ('Moving ', + files, + ' to ', + dst)
        else:
            print 'No Such File Exists'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:36:35+00:00Added an answer on May 27, 2026 at 1:36 am

    First, welcome to the community, and python! You might want to change your user name, especially if you frequent here. 🙂

    I suggest the following (stolen from Mr. Beazley):

    # genfind.py
    #
    # A function that generates files that match a given filename pattern
    
    import os
    import shutil
    import fnmatch
    
    def gen_find(filepat,top):
        for path, dirlist, filelist in os.walk(top):
            for name in fnmatch.filter(filelist,filepat):
                yield os.path.join(path,name)
    
    # Example use
    
    if __name__ == '__main__':
        src = 'O:\DATA\ASTER GDEM\Original\North America\UTM Zone 14\USA\Extracted' # input
        dst = 'O:\DATA\ASTER GDEM\Original\North America\UTM Zone 14\USA\Analyses' # desired     location
    
        filesToMove = gen_find("*dem.tif",src)
        for name in filesToMove:
            shutil.move(name, dst)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Python 2.7. I'm rather new to the python langauge. I have two
Im very new to C programing, but have limited experience with Python, Java, and
I have created a Python module that creates and populates several SQLite tables. Now,
I have been asked to build a rather simple form processor application that interacts
I have a python program that accesses a couchDB database, creates new documents and
I am new to network programming but old to Python. I have a simple
I am rather new to wx/python so please excuse if this is stupid or
I'm rather new to Django and I'm using Django 1.0. I have this: forms.py:
I am rather new to Linux device driver programmring, but for debugging purposes, I
I'm writing a library to process gaze tracking in Python, and I'm rather new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.