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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:21:31+00:00 2026-06-09T10:21:31+00:00

This is a stupid question, and I know it is, but for some reason

  • 0

This is a stupid question, and I know it is, but for some reason I can’t find any useful tutorials for running python from windows command prompt so I’ll have to ask you guys.
I have a script I need to run on all files starting FY*.txt or WS*.txt in one directory. I’ve tried going to the directory through command prompt and doing

for file in FY*.txt; do python my_script.py

which just informs me that ‘file’ is unexpected at this time. I’ve also tried

python my_script.py FY1.txt FY2.txt FY3.txt

with

import sys
inputfilenames=sys.argv[1:27]

for name in inputfilenames:
    datafile=open(name,'r')

as the way I open my files in the python script itself. This seems to only run the script on one file, rather than all of them.

I apologise for my ignorance, I really have no clue how to use command prompt to run python things. As well as answers, if anyone has any tutorial recommendations I would be very, very grateful.

  • 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-09T10:21:32+00:00Added an answer on June 9, 2026 at 10:21 am

    I’m not quite certain what that initial example is supposed to be, but to do that from the standard Windows command prompt, you could use something like this:

    for %G in (FY*.txt); do python my_script.py %G
    

    If you do something like this, you’ll need something like the following in your code:

    with open(sys.argv[1], 'r') as f:
        do_something_with(f)
    

    Alternatively, you could look into using the fileinput module to take a list of files as in your second example and process them. That is, inside your script you’d have something like:

    for line in fileinput.input():
        do_something_with(line)
    

    Or you could make the wildcard expression an argument and use the glob module, so you could run:

    python my_script.py FY*.txt
    

    And then in your script do something like:

    for file in glob.glob(sys.argv[1]):
         with open(file, 'r') as f:
             do_something_to(f)
    

    The glob could be run over multiple arguments:

    for files in([glob.glob(arg) for arg in sys.argv[1:]]):
        for file in files:
            with open(file, 'r') as f:
                do_something_to(f)
    

    which would allow you to execute:

    python my_script FY*.txt WS*.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

sorry if you'll find this question stupid, but I really need help. Here's some
i know this is a stupid question but i d'ont know how to do
I know this is a stupid question. But just out of curiosity, is there
I know this might be a stupid question, but here it goes. I always
This may be a stupid question to ask, but still I need to know
I know you may think this question is stupid, but I need to use
I know this is very stupid question, but I wanted to clarify this. Let's
This might look as a stupid question. But, I have a class with some
I know this might be a very stupid question but I am new to
This is probably a stupid question. I know I can wrap a ListView in

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.