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 8771999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:55:53+00:00 2026-06-13T17:55:53+00:00

I’m trying to write a Python code that will import LANDSAT satellite images into

  • 0

I’m trying to write a Python code that will import LANDSAT satellite images into Grass GIS by adapting this code: http://grass.osgeo.org/wiki/LANDSAT

LANDSAT tiles are downloaded as folders, each containing 7 tiff images (Band 1-7). I therefore have a directory which contains several subdirectories (one for each LANDSAT tile).

My code at present is as follows:

#!/usr/bin/python

import os
import sys
import glob
import grass.script as grass

def import_tifs(dirpath):

    for dirpath, dirname, filenames in os.walk(dirpath):
        for dirname in dirpath:

        dirname = os.path.join(dirpath,dirname)

            for file in os.listdir(dirname):
                if os.path.splitext(file)[-1] != '.TIF':
                    continue
                ffile = os.path.join(dirname, file)
                name = os.path.splitext(file)[0].split(dirname)[-1]

                grass.message('Importing %s -> %s@%s...' % (file, name, dirpath))

                grass.run_command('r.in.gdal',
                                  flags = 'o',
                                  input = ffile,
                                  output = name,
                                  quiet = True,
                                  overwrite = True)

def main():                                 
    if len(sys.argv) == 1:
        for directory in filter(os.path.isdir, os.listdir(os.getcwd())):
            import_tifs(directory)
    else:
        import_tifs(sys.argv[1])

if __name__ == "__main__":
    main()

I’m getting the following error:

Traceback (most recent call last):
  File "C:/Users/Simon/Documents/import_landsat2.py", line
40, in <module>
    main()
  File "C:/Users/Simon/Documents/import_landsat2.py", line
37, in main
    import_tifs(sys.argv[1])
  File "C:/Users/Simon/Documents/import_landsat2.py", line
17, in import_tifs
    for file in os.listdir(dirname):
WindowsError: [Error 3] The system cannot find the path
specified: 'dirpath\\C/*.*'

Can anyone explain what is happening and what I need to do to fix it, or suggest an alternative? Thanks.

  • 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-06-13T17:55:55+00:00Added an answer on June 13, 2026 at 5:55 pm

    I believe your main problem is that dirname in os.walk() returns a list (not a string), so your subsequent strings (namely dirname = os.path.join(dirpath,dirname)) are a bit malformed. Here is one possible alternative – to test this, I used the full path to the directory as sys.argv[1], but you can make it more dynamic to suit your case. Also, avoid using variable names such as file since they are Python keywords. I couldn’t test out your grass.* functions, but hopefully this will be a clear enough example so you can tweak how you need. os.walk() natively handles a lot of standard parsing, so you can remove some of the directory-manipulating functions:

    def import_tifs(dirpath):
      for dirpath, dirname, filenames in os.walk(dirpath):
        # Iterate through the files in the current dir returned by walk()
        for tif_file in filenames:
          # If the suffix is '.TIF', process
          if tif_file.upper().endswith('.tif'):
            # This will contain the full path to your file
            full_path = os.path.join(dirpath, tif_file)
    
            # tif_file will already contain the name, so you can call from here
            grass.message('Importing %s -> %s@%s...' % (full_path, tif_file, dirpath))
    
            grass.run_command('r.in.gdal',
                              flags = 'o',
                              input = full_path,
                              output = tif_file,
                              quiet = True,
                              overwrite = True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.