I want to know how to check if the string given is a path with a file name or not , the file name with extension is not on disk but will be created later, but since its not created I cannot use os.path.isfile(filepathsupplied)

so how should i check if string is specified with a valid file name in the end or not ?

You can chek that the parent directory exists

import os

def is_probably_valid(thepath):
    head, tail = os.path.split(thepath)
    return os.path.isdir(head)

The ultimate test is to create a file with this path (if it does not already exist). File creation may fail depending on the user's or folder's permission for example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.