コード例 #1
0
        public bool IsValidTarget(bool createIfMissing = true)
        {
            TargetDirectory.Refresh();
            if (!TargetDirectory.Exists)
            {
                if (createIfMissing)
                {
                    try
                    {
                        TargetDirectory.Create();
                        return(true); // If we were able to create the directory, it should be valid
                    }
#pragma warning disable CA1031        // Do not catch general exception types
                    catch (IOException)
                    { return(false); }
#pragma warning restore CA1031 // Do not catch general exception types
                }
                else
                {
                    return(false);
                }
            }
            try
            {
                var testDir = TargetDirectory.CreateSubdirectory("dirTest");
                testDir.Refresh();
                if (testDir.Exists)
                {
                    testDir.Delete();
                    return(true);
                }
            }
            catch (IOException)
            {
                return(false);
            }
            return(false);
        }