Answers for "check if a string is a file path"

C#
1

c# check if string is path or file

// get the file attributes for file or directory
FileAttributes attr = File.GetAttributes(@"c:\Temp");

//detect whether its a directory or file
if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
    MessageBox.Show("Its a directory");
else
    MessageBox.Show("Its a file");
Posted by: Guest on August-13-2020
-1

how to know if a string is valid file path python

import re

PATTERN = re.compile(r'((\w:)|(\.))((/(?!/)(?!/)|\\{2})[^\n?"|></\\:*]+)+')


def is_valid_path(string: str):
    if string and isinstance(string, str) and PATTERN.match(string):
        return True
    return False
Posted by: Guest on June-15-2021

Code answers related to "check if a string is a file path"

C# Answers by Framework

Browse Popular Code Answers by Language