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

  • Home
  • SEARCH
  • 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 8999069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:07:49+00:00 2026-06-16T00:07:49+00:00

I am trying to write a script that goes through a drive. The drive

  • 0

I am trying to write a script that goes through a drive. The drive has a folder structure similar to this:

| Folder 1
+--->Folder 1.txt
+--->Folder 1.nfo
| Folder 2
+--->Folder 2.doc
+--->Folder 2.nfo
+--->Folder 2.xls
| Folder 3
+--->Folder 3.txt
+--->Folder 3.nfo

older
What I am trying to do is read each of the files in the directory, then when I finish going through the directory, I want to write a log to a text file. I currently open each directory and file using the following:

logfile = open("log.txt")
for path, subdirs, files in os.walk(directory):
  txtfile = 0
  docfile = 0
  xlsfile = 0
  nfofile = 0
  for name in files:
    file = os.path.join(path, name)
    if file.endswith('.txt'):
      txtfile = 1
    elif file.endswith('.doc'):
      docfile = 1
    elif file.endswith('.xls'):
      xlsfile = 1
    elif file.endswith('.nfo'):
      nfofile = 1

    # if all files in a specific directory (Folder 1, Folder 2, etc) have been read, write line to log.txt

I am just not sure how to check the last file. The log will be used to see which files are missing from the directory. Any help on this would be greatly appreciated!

  • 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-16T00:07:50+00:00Added an answer on June 16, 2026 at 12:07 am

    You can list all the files in a directory like this: (taken from here)

    from os import listdir
    from os.path import isfile, join
    files = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
    

    Then check your file like this:

    if file == files[-1]: # do stuff
    

    Or, you can just iterate through files to make it easy, and when it finishes, log your stuff. I recommend doing this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a bash script that goes through a file line
I'm trying to write a simple script that goes checks the number of lines
I'm trying to write a script that contains this screen -S demo -d -m
I'm trying to write a script that prints out the file structure starting at
OK here goes, I am trying to write a script that, when a user
I'm trying to write a simple script that goes over a file (name list)
I am trying to write a script that does the following job: it goes
I'm trying to write a shell script which basically goes into a particular folder
I'm trying to write a script that informs the user when someone has logged
I am trying to write a script that will look through a set of

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.