当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.Create方法代码示例

本文整理汇总了C#中DirectoryInfo.Create方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.Create方法的具体用法?C# DirectoryInfo.Create怎么用?C# DirectoryInfo.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.Create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Copy

            public static void Copy(this DirectoryInfo dir, DirectoryInfo destinationDir, bool overwrite = true, bool copySubDirs = true)
            {
                if (!dir.Exists)
                {
                    throw new DirectoryNotFoundException(
                        "Source directory does not exist or could not be found."
                        );
                }

                // If the destination directory doesn't exist, create it.
                if (!destinationDir.Exists)
                    destinationDir.Create();

                // Get the files in the directory and copy them to the new location.
                foreach (FileInfo file in dir.EnumerateFiles())
                {
                    var targetpath = destinationDir.GetFile(file.Name).FullName;
                    if (overwrite || !File.Exists(targetpath))
                        file.CopyTo(targetpath, true);
                }

                // If copying subdirectories, copy them and their contents to new location.
                if (copySubDirs)
                    foreach (var subdir in dir.EnumerateDirectories())
                        subdir.Copy(destinationDir.CreateSubdirectory(subdir.Name));
            }
开发者ID:Craftitude-Team,项目名称:Craftitude,代码行数:26,代码来源:DirectoryInfoExtensions.cs

示例2: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     CatagoryTableAdapter adp = new CatagoryTableAdapter();
     DataTable dt = adp.GetCatagoryName();
     DirectoryInfo diAsset = new DirectoryInfo(Server.MapPath("Assets"));
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         string catagoryFolderName = dt.Rows[i][0].ToString();
         DirectoryInfo catagoryFolderDir = new DirectoryInfo(diAsset.FullName + "/" + catagoryFolderName);
         if (!catagoryFolderDir.Exists)
         {
             catagoryFolderDir.Create();
         }
         SubcatagoryTableAdapter subTa = new SubcatagoryTableAdapter();
         DataTable subDt = subTa.GetSubCatagoryNames(catagoryFolderName);
         for (int j = 0; j < subDt.Rows.Count; j++)
         {
             string subCatagoryFolderName = subDt.Rows[j][2].ToString();
             DirectoryInfo subCatagoryFolderDir = new DirectoryInfo(catagoryFolderDir + "/" + subCatagoryFolderName);
             if (!subCatagoryFolderDir.Exists)
             {
                 subCatagoryFolderDir.Create();
             }
         }
     }
 }
开发者ID:Raistlin97,项目名称:demo-projects,代码行数:26,代码来源:MasterPage.master.cs

示例3: CreateFolder

 public static void CreateFolder(string path)
 {
     DirectoryInfo di = new DirectoryInfo(path);
     if (di.Exists == false) {
         di.Create();
     }
 }
开发者ID:newkkd,项目名称:unityboot,代码行数:7,代码来源:PersistenceUtil.cs

示例4: OverwriteFile

	// Copy or overwrite destination file with source file.
	public static bool OverwriteFile(string srcFilePath, string destFilePath)
	{
		FileInfo fi = new FileInfo(srcFilePath);
		if ( ! fi.Exists )
        {
        	UnityEngine.Debug.LogError(string.Format("Wwise: Failed to overwrite. Source is missing: {0}.", srcFilePath));
    		return false;
        }

		DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(destFilePath));
		
		if ( ! di.Exists )
        {
            di.Create();
        }

        const bool IsToOverwrite = true;
        try
        {
        	fi.CopyTo(destFilePath, IsToOverwrite);		
    	}
    	catch (Exception ex)
        {
			UnityEngine.Debug.LogError(string.Format("Wwise: Error during installation: {0}.", ex.Message));
			return false;
        }

        return true;
	}	
开发者ID:juliendeville,项目名称:Lunatic,代码行数:30,代码来源:AkUnityPluginInstallerBase.cs

示例5: CopyDirectory

    /// <summary>
    /// Copy thư mục này đến thư mục khác
    /// </summary>
    /// <param name="ThuMucNguon"></param>
    /// <param name="ThucMucDich"></param>
    public static void CopyDirectory(DirectoryInfo ThuMucNguon, DirectoryInfo ThucMucDich)
    {
        try
        {
            if (!ThucMucDich.Exists)
            {
                ThucMucDich.Create();
            }
            FileInfo[] files = ThuMucNguon.GetFiles();
            foreach (FileInfo file in files)
            {
                if ((File.Exists(System.IO.Path.Combine(ThucMucDich.FullName, file.Name))) == false)
                {
                    file.CopyTo(Path.Combine(ThucMucDich.FullName, file.Name));
                }
            }
            //Xử lý thư mục con
            DirectoryInfo[] dirs = ThuMucNguon.GetDirectories();
            foreach (DirectoryInfo dir in dirs)
            {
                string ThucMucDichDir = Path.Combine(ThucMucDich.FullName, dir.Name);
                CopyDirectory(dir, new DirectoryInfo(ThucMucDichDir));
            }

        }
        catch { }
    }
开发者ID:trantrung2608,项目名称:ilinkbay,代码行数:32,代码来源:Folder.cs

示例6: btnUpload_Click

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            string fileName = FileUpload1.FileName;
            string prePath = Request["PrePath"];
            string savePath = Server.MapPath("~/" + prePath);
            DirectoryInfo dinfo = new DirectoryInfo(savePath);
            if (!dinfo.Exists) {
                dinfo.Create();
            }
             //Response.Write(savePath);
            if (FileUpload1.PostedFile.ContentLength > 10485760)
            {
                AgileFrame.Core.ScriptHelper.ResponseScript(Page, "closeBarWindow('" + pdivID + "');alert('上传的文件太大,不能超过10M。');", false);
            }
            else
            {
                FileUpload1.SaveAs(savePath + fileName);

                string js = "AddFileToParent('" + fileName + "','" + pdivID + "');closeBarWindow('" + pdivID + "');";
                AgileFrame.Core.ScriptHelper.ResponseScript(Page, js, false);
            }
        }
        catch {
            string js = "closeBarWindow('" + pdivID + "');";
            AgileFrame.Core.ScriptHelper.ResponseScript(Page, js, false);
        }
    }
开发者ID:Fred-Lee,项目名称:AppInOneBPM,代码行数:29,代码来源:UpFilesBf.aspx.cs

示例7: Main

    public static void Main(string[] args)
    {
        FileInfo file = new FileInfo(@"..\..\CopyDelete.cs");
        string fullPath =file.FullName;
        DirectoryInfo dir = new DirectoryInfo(@"..\..\");
        dir.CreateSubdirectory("backup");
        DirectoryInfo backupDir = new DirectoryInfo(@"..\..\backup");
        foreach (FileInfo subfile in backupDir.GetFiles())
        {
            subfile.Delete();
        }
        file.CopyTo(@"..\..\backup\CopyDelete_Backup.cs");

        DirectoryInfo tempDir = new DirectoryInfo(@"..\..\temp");
        tempDir.Create();
        FileInfo tempFile = new FileInfo(@"..\..\temp\temp.txt");
        FileStream fs = tempFile.Create();

        fs.Close();
        tempFile.Delete();
        tempDir.Delete(true);

        Console.WriteLine("All done.");
        Console.ReadLine();
    }
开发者ID:Nagato23,项目名称:CsBasic,代码行数:25,代码来源:CopyDelete.cs

示例8: CopyTo

    /// <summary>A DirectoryInfo extension method that copies to.</summary>
    /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception>
    /// <param name="obj">The obj to act on.</param>
    /// <param name="destDirName">Pathname of the destination directory.</param>
    /// <param name="searchPattern">A pattern specifying the search.</param>
    /// <param name="searchOption">The search option.</param>
    public static void CopyTo(this DirectoryInfo obj, string destDirName, string searchPattern, SearchOption searchOption)
    {
        var files = obj.GetFiles(searchPattern, searchOption);
        foreach (var file in files)
        {
            var outputFile = destDirName + file.FullName.Substring(obj.FullName.Length);
            var directory = new FileInfo(outputFile).Directory;

            if (directory == null)
            {
                throw new Exception("The directory cannot be null.");
            }

            if (!directory.Exists)
            {
                directory.Create();
            }

            file.CopyTo(outputFile);
        }

        // Ensure empty dir are also copied
        var directories = obj.GetDirectories(searchPattern, searchOption);
        foreach (var directory in directories)
        {
            var outputDirectory = destDirName + directory.FullName.Substring(obj.FullName.Length);
            var directoryInfo = new DirectoryInfo(outputDirectory);
            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }
        }
    }
开发者ID:fqybzhangji,项目名称:Z.ExtensionMethods,代码行数:39,代码来源:DirectoryInfo.CopyTo.cs

示例9: btn_Click

    protected void btn_Click(object sender, EventArgs e)
    {
        DirectoryInfo dir = new DirectoryInfo("C:\\IlinkbayForder");
        if (!dir.Exists)
            dir.Create();
        foreach (FileInfo file in dir.GetFiles())
        {
            file.Delete();
        }
        System.IO.FileStream fileReportHeader = new System.IO.FileStream(@"C:\\IlinkbayForder\\heReportHeader.rtf", System.IO.FileMode.Create);
        heReportHeader.Export(HtmlEditorExportFormat.Rtf, fileReportHeader);
        System.IO.FileStream fileReportFooter = new System.IO.FileStream(@"C:\\IlinkbayForder\\heReportFooter.rtf", System.IO.FileMode.Create);
        heReportFooter.Export(HtmlEditorExportFormat.Rtf, fileReportFooter);
        fileReportHeader.Close();
        fileReportFooter.Close();

        string rtfFooter = System.IO.File.ReadAllText(@"C:\\IlinkbayForder\\heReportFooter.rtf");
        string rtfHeader = System.IO.File.ReadAllText(@"C:\\IlinkbayForder\\heReportHeader.rtf");

        SqlHelper.ExecuteScalar( DataServices.ConnectString, "SY_exportsetting_Update", int.Parse(Session["ID"].ToString()), rtfHeader, heReportHeader.Html, rtfFooter, heReportFooter.Html, chkLandscape.Checked, cmbPagesKind.Value, txtFileName.Text);

        foreach (FileInfo file in dir.GetFiles())
        {
            file.Delete();
        }
        dir.Delete();
        CacheObject.buildCache_globalExportSetting();
    }
开发者ID:trantrung2608,项目名称:ilinkbay,代码行数:28,代码来源:SettingReportHeader.aspx.cs

示例10: CopyDirectory

    public void CopyDirectory(DirectoryInfo source, DirectoryInfo destination)
    {
        try
        {
        if (!destination.Exists)
        {
            destination.Create();
        }
        // Copy all files.
        FileInfo[] files = source.GetFiles();
        foreach (FileInfo file in files)
        {
            file.CopyTo(Path.Combine(destination.FullName,
            file.Name));
        }
        // Process subdirectories.
        DirectoryInfo[] dirs = source.GetDirectories();
        foreach (DirectoryInfo dir in dirs)
        {
             // Get destination directory.
             string destinationDir = Path.Combine(destination.FullName, dir.Name);

            // Call CopyDirectory() recursively.
            CopyDirectory(dir, new DirectoryInfo(destinationDir));
        }
        }
        catch(Exception ex)
        {
           ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript: error('Operation Failed'); ", true);
        }
    }
开发者ID:nikunjness,项目名称:cloudOS,代码行数:31,代码来源:fileview.aspx.cs

示例11: GetEntriesThenDelete

        public void GetEntriesThenDelete()
        {
            string testDirPath = GetTestFilePath();
            DirectoryInfo testDirInfo = new DirectoryInfo(testDirPath);
            testDirInfo.Create();
            string testDir1 = GetTestFileName();
            string testDir2 = GetTestFileName();
            string testFile1 = GetTestFileName();
            string testFile2 = GetTestFileName();
            string testFile3 = GetTestFileName();
            string testFile4 = GetTestFileName();
            string testFile5 = GetTestFileName();
            testDirInfo.CreateSubdirectory(testDir1);
            testDirInfo.CreateSubdirectory(testDir2);
            using (File.Create(Path.Combine(testDirPath, testFile1)))
            using (File.Create(Path.Combine(testDirPath, testFile2)))
            using (File.Create(Path.Combine(testDirPath, testFile3)))
            {
                string[] results;
                using (File.Create(Path.Combine(testDirPath, testFile4)))
                using (File.Create(Path.Combine(testDirPath, testFile5)))
                {
                    results = GetEntries(testDirPath);
                    Assert.NotNull(results);
                    Assert.NotEmpty(results);
                    if (TestFiles)
                    {
                        Assert.Contains(Path.Combine(testDirPath, testFile1), results);
                        Assert.Contains(Path.Combine(testDirPath, testFile2), results);
                        Assert.Contains(Path.Combine(testDirPath, testFile3), results);
                        Assert.Contains(Path.Combine(testDirPath, testFile4), results);
                        Assert.Contains(Path.Combine(testDirPath, testFile5), results);
                    }
                    if (TestDirectories)
                    {
                        Assert.Contains(Path.Combine(testDirPath, testDir1), results);
                        Assert.Contains(Path.Combine(testDirPath, testDir2), results);
                    }
                }

                File.Delete(Path.Combine(testDirPath, testFile4));
                File.Delete(Path.Combine(testDirPath, testFile5));
                FailSafeDirectoryOperations.DeleteDirectory(testDir1, true);

                results = GetEntries(testDirPath);
                Assert.NotNull(results);
                Assert.NotEmpty(results);
                if (TestFiles)
                {
                    Assert.Contains(Path.Combine(testDirPath, testFile1), results);
                    Assert.Contains(Path.Combine(testDirPath, testFile2), results);
                    Assert.Contains(Path.Combine(testDirPath, testFile3), results);
                }
                if (TestDirectories)
                {
                    Assert.Contains(Path.Combine(testDirPath, testDir2), results);
                }
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:59,代码来源:GetFileSystemEntries_str.cs

示例12: TempDirectory

 public TempDirectory()
 {
     var f = Path.GetTempFileName();
     var name = Path.GetFileNameWithoutExtension(f);
     File.Delete(f);
     Directory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), name));
     Directory.Create();
 }
开发者ID:github,项目名称:VisualStudio,代码行数:8,代码来源:TestBaseClass.cs

示例13: CheckURL

 //判斷檔案上傳路徑是否存在,若不存在則建立
 public static void CheckURL(string strPaht)
 {
     DirectoryInfo di = new DirectoryInfo(strPaht);
     if (!di.Exists)
     {
         di.Create();
     }
 }
开发者ID:AdamsChao,项目名称:netdb-localdev-proj,代码行数:9,代码来源:IMAUtil.cs

示例14: WindowsAttributeSetting

 public void WindowsAttributeSetting(FileAttributes attr)
 {
     var test = new DirectoryInfo(GetTestFilePath());
     test.Create();
     Set(test.FullName, attr);
     Assert.Equal(attr | FileAttributes.Directory, Get(test.FullName));
     Set(test.FullName, 0);
 }
开发者ID:shmao,项目名称:corefx,代码行数:8,代码来源:GetSetAttributes.cs

示例15: UpLoadFile

    public string UpLoadFile(HttpPostedFile inputFile, string filePath, string myfileName)
    {
        if (string.IsNullOrEmpty(filePath))
        {
            throw new ApplicationException("路径不能为空");
        }
        if (string.IsNullOrEmpty(myfileName))
        {
            throw new ApplicationException("文件名不能为空");
        }
        FileUpLoad fp = new FileUpLoad();

        //建立上传对象
        HttpPostedFile postedFile = inputFile;

        FileName = System.IO.Path.GetFileName(postedFile.FileName);
        FileExtension = System.IO.Path.GetExtension(FileName).ToUpper();

        //如果格式都不符合则返回
        if (!".JPG".Equals(FileExtension) && !".JPEG".Equals(FileExtension) && !".PNG".Equals(FileExtension) )
        {
            throw new ApplicationException("上传图片格式正确,请选择jpg,png格式的图片");
        }
        if (postedFile.ContentLength > 1024 * 1024 * 20)
        {
            throw new ApplicationException("最大只能上传20M文件");
        }

        if (myfileName != string.Empty)
        {
            FileName = myfileName+FileExtension;
        }

        string phyPath = HttpContext.Current.Server.MapPath("upload");

        //判断路径是否存在,若不存在则创建路径
        DirectoryInfo upDir = new DirectoryInfo(phyPath);
        if (!upDir.Exists)
        {
            upDir.Create();
        }

        try
        {
            string tempPath = Path.Combine(phyPath, filePath);
            string originalImagePath = Path.Combine(tempPath, FileName);
            string thumbnailPath = Path.Combine(tempPath,"thumbnail_" + FileName);
            //保存源文件
            postedFile.SaveAs(originalImagePath);

            ImageHelper.MakeThumbnail(originalImagePath, thumbnailPath,80,80,"W");
        }
        catch
        {
            throw new ApplicationException("上传失败!");
        }
        return "/upload/" + filePath + "/thumbnail_" + FileName;
    }
开发者ID:huaminglee,项目名称:Code,代码行数:58,代码来源:ImageUpload.cs


注:本文中的DirectoryInfo.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。