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


C# FileInfo.CopyTo方法代码示例

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


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

示例1: CopyFile

        private static void CopyFile(string source, string destination, bool overwrite, bool createMissingDirectories, ref int count)
        {
            FileInfo sourceFile = new FileInfo(source);

            //Console.WriteLine("Destination: " + destination);
            //Console.WriteLine("Directory Name: " + Path.GetDirectoryName(destination));
            //Console.WriteLine("File Name: " + Path.GetFileName(destination));
            //Console.WriteLine("Extension: " + Path.GetExtension(destination));

            if (String.IsNullOrWhiteSpace(Path.GetExtension(destination)))
            {
                // destination is a directory
                DirectoryInfo destinationDirectory = new DirectoryInfo(destination);

                if (createMissingDirectories && !destinationDirectory.Exists)
                    destinationDirectory.Create();

                string destinationFileName = Path.Combine(destinationDirectory.FullName, sourceFile.Name);
                sourceFile.CopyTo(destinationFileName, overwrite);
            }
            else
            {
                // destination is a file
                FileInfo destinationFile = new FileInfo(destination);

                if (createMissingDirectories && !destinationFile.Directory.Exists)
                    destinationFile.Directory.Create();

                string destinationFileName = destinationFile.FullName;
                sourceFile.CopyTo(destinationFileName, overwrite);
            }

            Console.WriteLine(sourceFile.FullName);
            ++count;
        }
开发者ID:billyzkid,项目名称:ncopy,代码行数:35,代码来源:Program.cs

示例2: TryCopyFile

        private bool TryCopyFile(FileInfo sourceFileInfo, DirectoryInfo targetDirectory)
        {
            var targetFileInfo = new FileInfo(Combine(targetDirectory, sourceFileInfo.Name));
              if (!targetFileInfo.Exists)
              {
            try
            {
              sourceFileInfo.CopyTo(targetFileInfo.FullName, true);
            }
            catch (Exception)
            {
              return false;
            }
              }

              if (targetFileInfo.Exists)
              {
            if (targetFileInfo.LastWriteTimeUtc < sourceFileInfo.LastWriteTimeUtc)
            {
              try
              {
            sourceFileInfo.CopyTo(targetFileInfo.FullName, true);
            Console.Write(".");
              }
              catch (Exception)
              {
            return false;
              }
            }
              }
              return true;
        }
开发者ID:Hammerheim,项目名称:Upbeat-File-Sync,代码行数:32,代码来源:Engine.cs

示例3: CreateTestFileAndCopyToFolder

        public FileInfo CreateTestFileAndCopyToFolder(string pathToCopyTo)
        {
            string path = Path.GetTempFileName();
            FileInfo fi1 = new FileInfo(path);

            //Create a file to write to.
            using (StreamWriter sw = fi1.CreateText())
            {
                sw.WriteLine("Title");
                sw.WriteLine("Lots of happenings");
                sw.WriteLine("Bazinga");
            }

            try
            {
                //Copy the file.
                fi1.CopyTo(pathToCopyTo+"\\TempFile.txt");
                FileInfo fi2 = new FileInfo(pathToCopyTo + "\\TempFile.txt");

                return fi2;
            }
            catch (Exception e)
            {
                Console.WriteLine("The process failed: {0}", e.ToString());
            }
            return null;
        }
开发者ID:x2find,项目名称:FileShare2Find,代码行数:27,代码来源:TestSupport.cs

示例4: CopyFile

 public static string CopyFile(FileInfo file)
 {
     string newFileName = PathBoss.ExtractPath() + file.Name + "_" + DateTime.Now.ToString("hhmmssfff") + "." + file.Extension;
     if (!File.Exists(newFileName))
         file.CopyTo(newFileName, true);
     return newFileName;
 }
开发者ID:GokhanBozkurt,项目名称:MyRepository,代码行数:7,代码来源:PathBoss.cs

示例5: BackupGame

 private static void BackupGame(Game game, string destDirName)
 {
     Debug.WriteLine(@"Starting file copy for " + game.Name);
     var allFiles = Directory.GetFiles(game.Path, "*.*", SearchOption.AllDirectories);
     foreach (var sourceFile in allFiles) {
         try {
             var index = sourceFile.IndexOf(game.RootFolder, StringComparison.CurrentCulture);
             var substring = sourceFile.Substring(index);
             var destinationFi = new FileInfo(destDirName + "\\" + substring);
             var destinationDir = destinationFi.DirectoryName;
             if (!Directory.Exists(destinationDir)) Directory.CreateDirectory(destinationDir);
             var file = new FileInfo(sourceFile);
             file.CopyTo(destinationFi.FullName, true);
             _progress.FilesComplete++;
             Messenger.Default.Send(_progress);
         }
         catch (IOException ex) {
             SBTErrorLogger.Log(ex.Message);
         }
         catch (NullReferenceException ex) {
             SBTErrorLogger.Log(ex.Message);
         }
     }
     Debug.WriteLine(@"Finished file copy for " + game.Name);
 }
开发者ID:rcornell,项目名称:SaveMonkey,代码行数:25,代码来源:BackupToFolder.cs

示例6: CompressNewSkins

        // Modified by K.G for phase2 tasks returned only one link of SkinPackage zip.
        public string CompressNewSkins(string newFolderName)
        {
            var offlineLinks = new OfflineLinks
                                    {
                                        portalLink = SkinManagerHelper.CompressFolder(portalUploadDir.FullName, skinRootDir.FullName, newFolderName, Res.NewPortalSkinPath),
                                        surveyLink = SkinManagerHelper.CompressFolder(surveyUploadDir.FullName, skinRootDir.FullName, newFolderName, Res.NewSurveySkinPath)
                                    };
            string communityzipPath = SkinManagerHelper.CompressFolder(communityUploadDir.FullName, skinRootDir.FullName, newFolderName, Res.NewCommunitySkinPath); //Added by K.G(24-11-2011) TO Support a third zip package called CommunitySkin.zip
            FileInfo[] portalSurveyZipFiles = { new FileInfo(offlineLinks.portalLink), new FileInfo(offlineLinks.surveyLink), new FileInfo(communityzipPath) };

            //Copied upadted Zipfiles to Skin Package.
            foreach (var zipFile in portalSurveyZipFiles)
            {
                if (zipFile.Length > 0)
                {
                    if (File.Exists(Path.Combine(skinPackageUploadDir.ToString(), zipFile.Name)))
                    {
                        File.Delete(Path.Combine(skinPackageUploadDir.ToString(), zipFile.Name));
                    }
                    zipFile.CopyTo(Path.Combine(skinPackageUploadDir.ToString(), zipFile.Name));
                }
            }
            string SkinPackageLink = SkinManagerHelper.CompressFolder(skinPackageUploadDir.FullName, skinRootDir.FullName, Res.SkinPackageToUploadPath, Res.NewSkinPackagePath);
            FileInfo SkinPackageFile = new FileInfo(SkinPackageLink);

            // Done K.G(25/11/2011) copied newly created zip package to portal skin so that it can also be uploaded in the folder under PortalStaging where the rest of the portal skin is uploaded
            SkinPackageFile.CopyTo(Path.Combine(portalUploadDir.ToString(), SkinPackageFile.Name));

            offlineLinks.portalLink = SkinManagerHelper.CompressFolder(portalUploadDir.FullName, skinRootDir.FullName, newFolderName, Res.NewPortalSkinPath);
            return SkinPackageLink;
        }
开发者ID:abhishekverma18,项目名称:TestRepo,代码行数:32,代码来源:SkinManager.cs

示例7: CopyDirectoryStructure

        private static void CopyDirectoryStructure(string SourcePath, string DestinationPath, bool overwriteexisting)
        {
            try
            {
                SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
                DestinationPath =
                    DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";

                if (Directory.Exists(SourcePath))
                {
                    if (Directory.Exists(DestinationPath) == false)
                        Directory.CreateDirectory(DestinationPath);

                    foreach (string fls in Directory.GetFiles(SourcePath))
                    {
                        FileInfo flinfo = new FileInfo(fls);

                        //resize the file                     

                        flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
                    }
                    foreach (string drs in Directory.GetDirectories(SourcePath))
                    {
                        DirectoryInfo diDi = new DirectoryInfo(drs);
                        CopyDirectoryStructure(drs, DestinationPath + diDi.Name, overwriteexisting);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:32,代码来源:ImageUploaderController.cs

示例8: CopyFile

        public void CopyFile(string path, string namefile)
        {
            try
            {
                fil = new FileInfo(path);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("Enter new path for copy: ");
                Console.ForegroundColor = ConsoleColor.White;
                string newPath = Console.ReadLine() + "\\" + namefile;
                Console.WriteLine(newPath);
                if (fil.Exists && Directory.Exists(newPath) == false)
                {
                    fil.CopyTo(newPath,true);
                    Console.WriteLine("File copied");
                }
                else
                {
                    Console.WriteLine("Error!!");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
开发者ID:VadymBratskyi,项目名称:MyRepository,代码行数:26,代码来源:WorkFile.cs

示例9: processStudies

 private void processStudies(string parentDir)
 {
     DicomUpdate dicomUpdate = new DicomUpdate();
     foreach (string dirs in Directory.GetDirectories(parentDir))
     {
         string dirName = Path.GetFileName(dirs);
         string targetOutputDirectory = _targetDir + "\\New_" + dirName;
         Directory.CreateDirectory(targetOutputDirectory);
         foreach (string file in Directory.GetFiles(dirs, "*", SearchOption.AllDirectories))
         {
             FileInfo fileInfo = new FileInfo(file);
             toolstripStatuslbl.Text = "Copying file " + fileInfo.Name;
             if (fileInfo.Extension == ".dcm")
             {
                 fileInfo.CopyTo(targetOutputDirectory + "\\" + fileInfo.Name, true);
             }
         }
         toolstripStatuslbl.Text = "Creating Update Objects";
         List<UpdateData> updateObjects = generateUpdateObjectList(targetOutputDirectory);
         foreach (UpdateData update in updateObjects)
         {
             toolstripStatuslbl.Text = "Should be updating now...";
             dicomUpdate.UpdateDicomFile(update);
         }
     }
     toolstripStatuslbl.Text = "Done";
 }
开发者ID:scottshea,项目名称:monodicom,代码行数:27,代码来源:QuickAnonymizationForm.cs

示例10: CheckFile

        private static List<string> CheckFile(ConfigInfo config)
        {
            List<string> newFileNames = new List<string>();
            foreach (var assInfo in config.AssemblyInfos)
            {
                string fileName = assInfo.FileName;
                FileInfo rFileinfo = new FileInfo(config.BaseUrl + fileName);
                FileInfo lFileInfo = new FileInfo(fileName);
                if (!rFileinfo.Exists)
                {
                    try
                    {
                        File.Delete(assInfo.FileName);
                        File.Delete(assInfo.FileName.ToUpper().Replace("ZIP", "DLL"));
                        File.Delete(assInfo.FileName.Replace("ZIP", "EXE"));
                    }
                    catch (Exception ex)
                    {

                    }
                }
                if (!lFileInfo.Exists || lFileInfo.LastWriteTime < rFileinfo.LastWriteTime)
                {
                    try
                    {
                        newFileNames.Add(assInfo.FileName);
                        rFileinfo.CopyTo(assInfo.FileName, true);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            return newFileNames;
        }
开发者ID:RainSong,项目名称:Sample,代码行数:35,代码来源:Download.cs

示例11: CopyFile

        public static bool CopyFile(string newFile, string oldFile)
        {
            var newfile = new FileInfo(newFile);
            var oldfile = new FileInfo(oldFile);
            string errorMsg = "";
            var f2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, oldFile);
            f2.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, newFile);

            try
            {
                f2.Demand();
            }
            catch (SecurityException s)
            {
                Console.WriteLine(s.Message);
            }

               for (int x = 0; x < 100; x++)
               {
                    try
                    {
                       File.Delete(oldfile.FullName);
                       newfile.CopyTo(oldfile.FullName, true);
                       return true;
                    }
                    catch(Exception e)
                    {
                        errorMsg = e.Message + " :   " + e.InnerException;
                        Thread.Sleep(200);
                    }
               }
            Data.Logger(errorMsg);
               return false;
        }
开发者ID:cengonurozkan,项目名称:vFenseAgent-win,代码行数:34,代码来源:Tools.cs

示例12: LosslessCompress

    private static void LosslessCompress(FileInfo file, bool progressive)
    {
      FileInfo output = new FileInfo(Path.GetTempFileName());

      try
      {
        int result = NativeJpegOptimizer.Optimize(file.FullName, output.FullName, progressive);

        if (result == 1)
          throw new MagickCorruptImageErrorException("Unable to decompress the jpeg file.", null);

        if (result == 2)
          throw new MagickCorruptImageErrorException("Unable to compress the jpeg file.", null);

        if (result != 0)
          return;

        output.Refresh();
        if (output.Length < file.Length)
          output.CopyTo(file.FullName, true);

        file.Refresh();
      }
      finally
      {
        FileHelper.Delete(output);
      }
    }
开发者ID:dlemstra,项目名称:Magick.NET,代码行数:28,代码来源:JpegOptimizer.cs

示例13: Sign

        private void Sign(string filename)
        {
            try
            {
                string p = @"<RSAKeyValue><Modulus>wJqUfZ3Iry4fV6p1bjO817u2/HE1zCmsnguE0Of+1Dzzcc+L3psx1PsDmXlxcLU9E4+ndbIacC2XMWlrIaLSikIJgfMwuvBej18HrrNATpKHwprUpRMU3P9ug5iemz0pyHA3Nr+keCU/b/HsFmido6R1cuBSDd6RYtlK1Xx+KlU=</Modulus><Exponent>AQAB</Exponent><P>+37HaPakQZN5GKh7Jf8a4b/3kqHIynsd0CYVNN0ax3qqRneEdyhfC2CzJGjv6UPOyAXZHn/T8kWpcSfLbqMlqw==</P><Q>xA3Byhq3RTP4YJYBdri/AZMBpRTiV+xSKi1XLz9m0QsNE5ctuwhbD3wY3YlMdIAbOAVewrxjTJg336z2JHPv/w==</Q><DP>VPgKa14ZNMacfUY/BSFhdbAj9viOHEroUbDsLUYejBLXgKNUr+WF5xQusjh6BfeQ32eKaZGKjCoZC1AEnUalrQ==</DP><DQ>BDAnC6I2eAv8KlQKA/c+XVI+nsArdaVeu/fr/N5l2+FYjiqUl4I+L75+6XydXX+/FRtIQvCzTleSGf0f5Pd1EQ==</DQ><InverseQ>xwGNcideNnj6XrDwLFSv3y7CMq2vMzuYxaObaNTU9sh1PTKVMRpiwdKWKpwnstXmDaSduBVw4EvfNlaz+SzUuw==</InverseQ><D>AJc4x13ZhLgGfpVWQN1Fwf+gYwvR12t1TRLJ+H4NqQb61CmHy0n8kCOo8iqOL4NOyaWSJOlD7X4mTY9+NZ8zOBn2Wij0r606Omw+/rlU986lwcxdBiw3y/LND3gowf1gR3Ei9K0eYsHTZZ9Ry9pmqowXi1DG916MBWSuwAbiOw0=</D></RSAKeyValue>";
                RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
                rsa.FromXmlString(p);

                FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.None);

                SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
                byte[] hash = sha1.ComputeHash(fs);

                byte[] b = rsa.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
                fs.Close();

                FileInfo fi = new FileInfo(filename);
                fi.CopyTo(filename + ".p1s", true);
                FileStream fo = new FileStream(filename + ".p1s", FileMode.Append, FileAccess.Write, FileShare.None);
                fo.Write(b, 0, b.Length);
                fo.Close();

                MessageBox.Show(filename + ".p1s is successfully created.");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
开发者ID:zhuangyy,项目名称:Motion,代码行数:29,代码来源:UpdateMainForm.cs

示例14: executeTest

        public override void executeTest( )
        {
            Console.WriteLine("Test Case: Change Encoding of the xml file to UTF -7");
            try
            {
                string holodeckPath;
                holodeckPath = (string) Registry.LocalMachine.OpenSubKey ("Software\\HolodeckEE", true).GetValue ("InstallPath");

                FunctionsXMLFilePath = string.Concat(holodeckPath,"\\function_db\\functions.xml");

                FunctionsXMLBackupFilePath = string.Concat(FunctionsXMLFilePath,".bak");

                modifyThisFile = new FileInfo(FunctionsXMLFilePath);
                modifyThisFile.Attributes = FileAttributes.Normal;
                modifyThisFile.CopyTo(FunctionsXMLBackupFilePath);

                //modify xml here
                FunctionXMLNavigator FuncXMLNav = new FunctionXMLNavigator();
                FunctionsXMLFilePath = modifyThisFile.FullName;
                FuncXMLNav.ValidateXmlDocument(FunctionsXMLFilePath);
                FuncXMLNav.parseXmlDocument(FunctionsXMLFilePath);

                //saving the functions.xml
                FuncXMLNav.saveFunctionXmlDocument(FuncXMLNav,FunctionsXMLFilePath,"UTF-7",true);

                try
                {	//add code here which will launch Holodeck
                    Holodeck.HolodeckProcess.Start();
                }
                catch(Holodeck.HolodeckExceptions.CannotStartHolodeckException ex)
                {
                    Console.WriteLine("Cannot Start Holodeck Exception thrown ");
                    Console.WriteLine(ex.Message);
                }

            }
            catch(HolodeckExceptions.IncorrectRegistryException e)
            {
                Console.WriteLine(" Incorrect Registry Exception caught.... : " + e.Message);
                Console.WriteLine("Details: " + e.StackTrace);
            }
            catch(FileNotFoundException f)
            {
                Console.WriteLine(" File Not Found Exception caught.... : " + f.Message);
                Console.WriteLine("Details: " + f.StackTrace);
            }
            finally
            {
                if(Holodeck.HolodeckProcess.IsRunning ())
                {
                    Holodeck.HolodeckProcess.Stop();
                }
                //reverting back to original
                modifyThisFile.Delete();

                FileInfo regainOriginal = new FileInfo(FunctionsXMLBackupFilePath);
                regainOriginal.MoveTo(FunctionsXMLFilePath);

            }
        }
开发者ID:uvbs,项目名称:Holodeck,代码行数:60,代码来源:FunctionXMLTest3.cs

示例15: CopyDirectory

        public static bool CopyDirectory(string sourcePath, string destinationPath, bool overwriteexisting)
        {
            bool ret = false;
            try
            {
                sourcePath = sourcePath.EndsWith(@"\") ? sourcePath : sourcePath + @"\";
                destinationPath = destinationPath.EndsWith(@"\") ? destinationPath : destinationPath + @"\";

                if (IsExistDirectory(sourcePath))
                {
                    if (IsExistDirectory(destinationPath) == false)
                        Directory.CreateDirectory(destinationPath);

                    foreach (string fls in Directory.GetFiles(sourcePath))
                    {
                        FileInfo flinfo = new FileInfo(fls);
                        flinfo.CopyTo(destinationPath + flinfo.Name, overwriteexisting);
                    }
                    foreach (string drs in Directory.GetDirectories(sourcePath))
                    {
                        DirectoryInfo drinfo = new DirectoryInfo(drs);
                        if (CopyDirectory(drs, destinationPath + drinfo.Name, overwriteexisting) == false)
                            ret = false;
                    }
                }
                ret = true;
            }
            catch (Exception ex)
            {
                CooperationWrapper.WriteLog(ex);
                ret = false;
            }
            return ret;
        }
开发者ID:Tony-Liang,项目名称:Common,代码行数:34,代码来源:DirectoryHelper.cs


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