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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:06:57+00:00 2026-06-08T08:06:57+00:00

I have a program in python 2.7 that is writing certain files and directories

  • 0

I have a program in python 2.7 that is writing certain files and directories base on user input. I need to make sure that the files and directories are valid for both linux and windows as the files will be exchanged through the two operating systems. The files will originally be created in linux and manual moved to windows.

I have checked through Python docs, stack exchange, and several pages of google without turning up any usable information which is strange because I would imagine this would be a fairly common issue.

Is there an easy solution?

Edit:
I would like to validate the directory-filename incase a user enters a path that does not work for linux or windows. As an example if a user enters “Folder1/This:Error/File.txt” the program will see this as an error.

The program will run in Linux and write the files in linux but later the files will be moved to windows. The differences in forward/back-slashes is a non-issue, but other characters that may work for linux but not windows would present a problem.

Also, often times the files or directories will not be present (as they are about to be created) so I need to check that path, held in a string, would be a valid path.

  • 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-08T08:06:58+00:00Added an answer on June 8, 2026 at 8:06 am

    I’m not sure there is a built-in function that does what you want, so you might need to do it yourself.

    Your best bet is to create a “whitelist” of characters that you know will be valid. For example: alphanumerics, underscores, etc. Then, if the filename given by the user has any characters NOT in this list, throw up an error. It doesn’t matter if this whitelist leaves out a few characters that should work; getting it right 95% (as long as the 5% are false negatives) should be fine.

    Keep in mind there might be some issues besides just characters that are invalid. See this question for various considerations when writing such a function.

    Finally, one solution is to name the file yourself, rather than allow the user to do it. Depending on your situation, you might be able to store the file with one filename, but in the application, you see it referred to by a different name. Of course, if the user will be accessing these files directly outside of your program, this could be confusing.

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

Sidebar

Related Questions

I have a problem: I am writing a program in Python 3.2 that requires
I have a completely non-interactive python program that takes some command-line options and input
Program Details: I am writing a program for python that will need to look
I have program that requires Python 3, but I develop Django and it uses
I have a Python program that executes a large MySQL statement. How do I
I have a python program that takes the md5 & sha1 hash values of
I have a python program that must work on Windows and Linux. There are
I have a python program that opens several urls in seperate tabs in a
I have a python program that is going to eat a lot of memory,
I have a python program that I am currently working on which is working

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.