Dev2.PathOperations.Dev2ActivityIOPathUtils.IsDirectory C# (CSharp) Method

IsDirectory() public static method

Is the path a directory or file?
public static IsDirectory ( string path ) : bool
path string
return bool
        public static bool IsDirectory(string path)
        {
            bool result = false;

            if(path.Contains("ftp://") || path.Contains("ftps://") || path.Contains("sftp://"))
            {
                var ftpUri = new Uri(path);
                var isFile = ftpUri.LocalPath.Contains(".");
                return !isFile;
            }

            if(path.EndsWith("\\") || path.EndsWith("/"))
            {
                result = true;
            }
            else
            {
                int idx = path.LastIndexOf("\\", StringComparison.Ordinal);

                if(idx > 0)
                {
                    if(!path.Substring(idx).Contains("."))
                    {
                        result = true;
                    }
                }
                else
                {
                    idx = path.LastIndexOf("/", StringComparison.Ordinal);
                    if(idx > 0)
                    {
                        if(!path.Substring(idx).Contains("."))
                        {
                            result = true;
                        }
                    }
                }
            }

            return result;
        }

Usage Example

        public enPathType PathIs(IActivityIOPath path)
        {
            var result = enPathType.File;

            if (path.Path.StartsWith("\\\\"))
            {
                if (Dev2ActivityIOPathUtils.IsDirectory(path.Path))
                {
                    result = enPathType.Directory;
                }
            }
            else
            {
                if (FileExist(path) || DirectoryExist(path))
                {
                    result = IsDirectory(path, result);
                }
                else
                {
                    if (Dev2ActivityIOPathUtils.IsDirectory(path.Path))
                    {
                        result = enPathType.Directory;
                    }
                }
            }

            return(result);
        }
All Usage Examples Of Dev2.PathOperations.Dev2ActivityIOPathUtils::IsDirectory