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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:55:47+00:00 2026-06-09T02:55:47+00:00

I have Windows PC. My script should identify sequency number of the file passed

  • 0

I have Windows PC. My script should identify sequency number of the file passed in the command line in the folder, i.e.

myscript.py \\network-drive\files\Long-long.file.name.with.numbers.txt

Folder content is the following:

\\network-drive\files\
    folder1
    folder2
    file1
    file2
    Long.long.file.name.with.numbers.txt
    file3
    file4

My script should identify sequence number of the file given in the command line, i.e. should return 5 (folders are also to be counted; assumption is that files are sorted by their names).

Upd. I’ve stopped with the following:

import sys
import os.path

if sys.argv[1]: # regardless of this verification, exception happens if argument is not passed
    head, tail = os.path.split(sys.argv[1])
    print head
    print os.listdir(head)

The list returned by listdir doesn’t allow me to identify what is folder and what is file. So, I can not sort them properly.

  • 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-09T02:55:49+00:00Added an answer on June 9, 2026 at 2:55 am

    It looks like something like this should work:

    import os
    import glob
    import sys
    import os.path as path
    
    try:
        directory,file = path.split( sys.argv[1] )
        def sort_func(fname):
            """
            Russian directories , english directories, russian files then english files
            although, honestly I don't know how russian files will actually be sorted ...
            """
            fullname = path.join(directory,fname)
            isRussian = any(ord(x) > 127 for x in fullname)
            isDirectory = path.isdir(fullname)
            return ( not isDirectory, not isRussian, fullname)
    
        files = sorted( os.listdir(directory), key=sort_func)
        print ( files.index(file) + 1 )
    
    except IndexError:
        print "oops, no commandline arguments"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a python script which should invoke a .exe file to get some
Battling with a windows command line script I just can't get to work. Basically
I have one windows batch script where I am calling two other batch script.
I have Windows box and I wish to invoke a .sh script on a
I would like to have a Windows 2003 server fire a script to fire
I have an f# script using Windows Forms and I want it to run
We have a script right now which our Windows users run on a Linux
I have a script to get and set user's Windows environment variables on other
I have a prolog script and runs without any problems on Windows with swi-prolog,
I have a PHP script running on XAMPP in Windows XP that will open

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.