當前位置: 首頁>>代碼示例>>C#>>正文


C# DirectoryInfo.Mkdirs方法代碼示例

本文整理匯總了C#中System.IO.DirectoryInfo.Mkdirs方法的典型用法代碼示例。如果您正苦於以下問題:C# DirectoryInfo.Mkdirs方法的具體用法?C# DirectoryInfo.Mkdirs怎麽用?C# DirectoryInfo.Mkdirs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.Mkdirs方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: MkDirs

        public void MkDirs()
        {
            var dir = Path.Combine(_mkDirsPath, "subDir1/subDir2");

            var dirInfo = new DirectoryInfo(dir);
            Assert.IsFalse(dirInfo.Exists);

            var ret = dirInfo.Mkdirs();

            Assert.IsTrue(ret);
            Assert.IsTrue(dirInfo.Exists);
        }
開發者ID:dev218,項目名稱:GitSharp,代碼行數:12,代碼來源:ExtensionsFixture.cs

示例2: testEmptyIfRootIsEmpty

        public void testEmptyIfRootIsEmpty()
        {
            string path = Path.Combine(trash.FullName, "not-existing-File");
            var di = new DirectoryInfo(path);
            Assert.IsFalse(di.Exists);

            di.Mkdirs();
            di.Refresh();
            Assert.IsTrue(di.Exists);

            var fti = new FileTreeIterator(di);
            Assert.IsTrue(fti.first());
            Assert.IsTrue(fti.eof());
        }
開發者ID:dev218,項目名稱:GitSharp,代碼行數:14,代碼來源:FileTreeIteratorTest.cs

示例3: renameAndOpenPack

        public PackLock renameAndOpenPack(string lockMessage)
        {
            if (!_keepEmpty && _entryCount == 0)
            {
                CleanupTemporaryFiles();
                return null;
            }

            MessageDigest d = Constants.newMessageDigest();
            var oeBytes = new byte[Constants.OBJECT_ID_LENGTH];
            for (int i = 0; i < _entryCount; i++)
            {
                PackedObjectInfo oe = _entries[i];
                oe.copyRawTo(oeBytes, 0);
                d.Update(oeBytes);
            }

            string name = ObjectId.FromRaw(d.Digest()).Name;
            var packDir = new DirectoryInfo(Path.Combine(_repo.ObjectsDirectory.ToString(), "pack"));
            var finalPack = new FileInfo(Path.Combine(packDir.ToString(), "pack-" + GetPackFileName(name)));
            var finalIdx = new FileInfo(Path.Combine(packDir.ToString(), "pack-" + GetIndexFileName(name)));
            var keep = new PackLock(finalPack);

            if (!packDir.Exists && !packDir.Mkdirs() && !packDir.Exists)
            {
                CleanupTemporaryFiles();
                throw new IOException("Cannot Create " + packDir);
            }

            if (finalPack.Exists)
            {
                CleanupTemporaryFiles();
                return null;
            }

            if (lockMessage != null)
            {
                try
                {
                    if (!keep.Lock(lockMessage))
                    {
                        throw new IOException("Cannot lock pack in " + finalPack);
                    }
                }
                catch (IOException)
                {
                    CleanupTemporaryFiles();
                    throw;
                }
            }

            if (!_dstPack.RenameTo(finalPack.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                throw new IOException("Cannot move pack to " + finalPack);
            }

            if (!_dstIdx.RenameTo(finalIdx.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                finalPack.Delete();
                //if (finalPack.Exists)
                // TODO: [caytchen]  finalPack.deleteOnExit();
                throw new IOException("Cannot move index to " + finalIdx);
            }

            try
            {
                _repo.OpenPack(finalPack, finalIdx);
            }
            catch (IOException)
            {
                keep.Unlock();
                finalPack.Delete();
                finalIdx.Delete();
                throw;
            }

            return lockMessage != null ? keep : null;
        }
開發者ID:georgeck,項目名稱:GitSharp,代碼行數:82,代碼來源:IndexPack.cs

示例4: renameAndOpenPack

        /// <summary>
        /// Rename the pack to it's final name and location and open it.
        /// <para/>
        /// If the call completes successfully the repository this IndexPack instance
        /// was created with will have the objects in the pack available for reading
        /// and use, without needing to scan for packs.
        /// </summary>
        /// <param name="lockMessage">
        /// message to place in the pack-*.keep file. If null, no lock
        /// will be created, and this method returns null.
        /// </param>
        /// <returns>the pack lock object, if lockMessage is not null.</returns>
        public PackLock renameAndOpenPack(string lockMessage)
        {
            if (!_keepEmpty && _entryCount == 0)
            {
                CleanupTemporaryFiles();
                return null;
            }

            MessageDigest d = Constants.newMessageDigest();
            var oeBytes = new byte[Constants.OBJECT_ID_LENGTH];
            for (int i = 0; i < _entryCount; i++)
            {
                PackedObjectInfo oe = _entries[i];
                oe.copyRawTo(oeBytes, 0);
                d.Update(oeBytes);
            }

            string name = ObjectId.FromRaw(d.Digest()).Name;
            var packDir = new DirectoryInfo(Path.Combine(_repo.ObjectsDirectory.ToString(), "pack"));
            var finalPack = new FileInfo(Path.Combine(packDir.ToString(), "pack-" + GetPackFileName(name)));
            var finalIdx = new FileInfo(Path.Combine(packDir.ToString(), "pack-" + GetIndexFileName(name)));
            var keep = new PackLock(finalPack);

            if (!packDir.Exists && !packDir.Mkdirs() && !packDir.Exists)
            {
                // The objects/pack directory isn't present, and we are unable
                // to create it. There is no way to move this pack in.
                //
                CleanupTemporaryFiles();
                throw new IOException("Cannot Create " + packDir);
            }

            if (finalPack.Exists)
            {
                // If the pack is already present we should never replace it.
                //
                CleanupTemporaryFiles();
                return null;
            }

            if (lockMessage != null)
            {
                // If we have a reason to create a keep file for this pack, do
                // so, or fail fast and don't put the pack in place.
                //
                try
                {
                    if (!keep.Lock(lockMessage))
                    {
                        throw new IOException("Cannot lock pack in " + finalPack);
                    }
                }
                catch (IOException)
                {
                    CleanupTemporaryFiles();
                    throw;
                }
            }

            if (!_dstPack.RenameTo(finalPack.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                throw new IOException("Cannot move pack to " + finalPack);
            }

            if (!_dstIdx.RenameTo(finalIdx.ToString()))
            {
                CleanupTemporaryFiles();
                keep.Unlock();
                finalPack.Delete();
                //if (finalPack.Exists)
                // TODO: [caytchen]  finalPack.deleteOnExit();
                throw new IOException("Cannot move index to " + finalIdx);
            }

            try
            {
                _repo.OpenPack(finalPack, finalIdx);
            }
            catch (IOException)
            {
                keep.Unlock();
                finalPack.Delete();
                finalIdx.Delete();
                throw;
            }

//.........這裏部分代碼省略.........
開發者ID:deodelacruz,項目名稱:GitSharp,代碼行數:101,代碼來源:IndexPack.cs


注:本文中的System.IO.DirectoryInfo.Mkdirs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。