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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:46:50+00:00 2026-06-12T10:46:50+00:00

I am trying to write a Python script that can move and copy files

  • 0

I am trying to write a Python script that can move and copy files on a remote Linux server. However, I can’t assume that everyone running the script (on Windows) will have mapped this server to the same letter. Rather than prompting users for the correct letter, I want to simply access the server by its network URL, the one that the drive letter is mapped to. So, for instance, if I have mapped the server’s URL

\\name-of-machine.site.company.com

To be drive S:\, I want to access, say, the file S:\var\SomeFile.txt in a drive-letter agnostic manner. I have looked around and the general recommendation seems to be to use UNC notation:

f = open(r"\\name-of-machine.site.company.com\var\SomeFile.txt", "w")

But if I try this, an IOError saying there is no such file or directory. If I try using the server’s IP address instead (not the real address, but similar):

f = open(r"\\10.1.123.149\var\SomeFile.txt", "w")

I get, after a long pause, an IO Error: “invalid mode (‘w’) or filename”. Why are these notations not working, and how can I access this server (ideally as if it were a local drive) by its URL?

  • 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-12T10:46:52+00:00Added an answer on June 12, 2026 at 10:46 am

    Not a very elegant solution, but you could just try all the drives?

    From here:

    import win32api
    
    drives = win32api.GetLogicalDriveStrings()
    drives = drives.split('\000')[:-1]
    print drives
    

    Then you could use os.path.exists() on every drive:\var\SomeFile.txt until you find the right one.

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

Sidebar

Related Questions

I'm trying write a python 2.7 script, that connects to a server via SSL
I'm trying to write a Python script that uses a particular external application belonging
I am trying to write a python script that takes record data like this
I am trying to write a python script that will change my cwd to
I'm trying to write a simple Python script that inserts .odt documents into an
I'm trying to learn python, so I decided to write a script that could
I'm trying to write a python script that modifies the contents of <script> tag
I'm trying to write a Unix script that will let me print the Python
In the process of trying to write a Python script that uses PIL today,
I'm trying to write a Python script that will enable me to start the

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.