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


C# FileInfo.MoveTo方法代码示例

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


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

示例1: Log

 public static void Log(string entry)
 {
     if (console_mode)
     {
         Console.WriteLine(entry);
     }
     StreamWriter writer = null;
     try
     {
         FileInfo info = new FileInfo(fileName);
         if (info.Exists && (info.Length >= 0x100000))
         {
             string path = fileName + ".old";
             File.Delete(path);
             info.MoveTo(path);
         }
         writer = new StreamWriter(fileName, true);
         writer.WriteLine("[{0:yyyy-MM-dd HH:mm:ss}] {1}", DateTime.Now, entry);
         writer.Flush();
     }
     catch (Exception)
     {
     }
     finally
     {
         if (writer != null)
         {
             writer.Close();
         }
     }
 }
开发者ID:BGCX261,项目名称:zoggr-svn-to-git,代码行数:31,代码来源:ZoggrLogger.cs

示例2: ArchiveException

        /// <summary>
        /// Archives the exception report.
        /// The name of the PDF file is modified to make it easier to identify.
        /// </summary>
        /// <param name="pdfFile">The PDF file.</param>
        /// <param name="archiveDirectory">The archive directory.</param>
        public static void ArchiveException(FileInfo pdfFile, string archiveDirectory)
        {
            // Create a new subdirectory in the archive directory
            // This is based on the date of the report being archived
            DirectoryInfo di = new DirectoryInfo(archiveDirectory);
            string archiveFileName = pdfFile.Name;
            string newSubFolder = ParseFolderName(archiveFileName);
            try
            {
                di.CreateSubdirectory(newSubFolder);
            }
            catch (Exception ex)
            {
                // The folder already exists so don't create it
            }

            // Create destination path
            // Insert _EXCEPT into file name
            // This will make it easier to identify as an exception in the archive folder
            string destFileName = archiveFileName.Insert(archiveFileName.IndexOf("."), "_EXCEPT");
            string destFullPath = archiveDirectory + "\\" + newSubFolder + "\\" + destFileName;

            // Move the file to the archive directory
            try
            {
                pdfFile.MoveTo(destFullPath);
            }
            catch (Exception ex)
            {
            }
        }
开发者ID:RonFields72,项目名称:EmailACHReportsToVendors,代码行数:37,代码来源:FileHelper.cs

示例3: Execute

        public void Execute()
        {
            var files = Directory.GetFiles(SourceFolder, "*.jpg");
            foreach (var file in files)
            {
                try
                {
                    DateTime dt;
                    using (var em = new ExifManager(file))
                    {
                        dt = em.DateTimeOriginal;
                    }

                    if (dt == DateTime.MinValue) continue;

                    var fi = new FileInfo(file);
                    var newName = Path.Combine(DestinantionFolder,
                                               string.Format("{0}.jpg", dt.ToString("yyyy-MM-dd_HH.mm.ss")));
                    fi.MoveTo(newName);
                }
                catch
                {
                }
            }

        }
开发者ID:shinetechchina-tj,项目名称:WinSir.Tools.Photos,代码行数:26,代码来源:RenamedByExif.cs

示例4: AfterParse

        private void AfterParse(IAsyncResult result)
        {
            try
            {
                Watcher watcher = result.AsyncState as Watcher;

                FileInfo file = new FileInfo(watcher.CurrentFile);

                switch (watcher.LastAction)
                {
                    case "0":
                        break;
                    case "1":
                        file.Delete();
                        break;
                    case "2":
                        {
                            string destFilename = Path.Combine(watcher.LastPath, file.Name);
                            File.Delete(destFilename);
                            file.MoveTo(destFilename);
                        }
                        break;
                }
                file = null;
            }
            catch
            {

            }
        }
开发者ID:keenkid,项目名称:BankReportService,代码行数:30,代码来源:FswWrapper.cs

示例5: MigrateLegacyDictionaries

        private static void MigrateLegacyDictionaries()
        {
            var oldNewDictionaryFileNames = new List<Tuple<string, string>>
            {
                new Tuple<string, string>("AmericanEnglish.dic", "EnglishUS.dic"),
                new Tuple<string, string>("BritishEnglish.dic", "EnglishUK.dic"),
                new Tuple<string, string>("CanadianEnglish.dic", "EnglishCanada.dic"),
            };

            foreach (var oldNewFileName in oldNewDictionaryFileNames)
            {
                var oldDictionaryPath = GetUserDictionaryPath(oldNewFileName.Item1);
                var oldFileInfo = new FileInfo(oldDictionaryPath);
                var newDictionaryPath = GetUserDictionaryPath(oldNewFileName.Item2);
                var newFileInfo = new FileInfo(newDictionaryPath);
                if (oldFileInfo.Exists)
                {
                    Log.InfoFormat("Old user dictionary file found at '{0}'", oldDictionaryPath);

                    //Delete new user dictionary
                    if (newFileInfo.Exists)
                    {
                        Log.InfoFormat("New user dictionary file also found at '{0}' - deleting this file", newDictionaryPath);
                        newFileInfo.Delete();
                    }

                    //Rename old user dictionary
                    Log.InfoFormat("Renaming old user dictionary file '{0}' to '{1}'", oldDictionaryPath, newDictionaryPath);
                    oldFileInfo.MoveTo(newDictionaryPath);
                }
            }
        }
开发者ID:masonyang,项目名称:OptiKey,代码行数:32,代码来源:DictionaryService.cs

示例6: Upload

        public async Task<HttpResponseMessage> Upload()//int clientSurveyId
        {
            HttpRequestMessage request = this.Request;
            if (!request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType));
            }

            string root = Classes.Utility.ImagesFolder; //System.Web.HttpContext.Current.Server.MapPath("~/App_Data/uploads");
            //validate if the upload folder exists. If not, create one
            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            var provider = new MultipartFormDataStreamProvider(root);

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);
                List<string> newFiles = new List<string>();
                int clientSurveyId =0;
                // Save each images files separately instead of a single multipart file
                foreach (MultipartFileData file in provider.FileData)
                {
                    //Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                    //Trace.WriteLine("Server file path: " + file.LocalFileName);
                    string fileName = file.Headers.ContentDisposition.FileName;
                    var newName = fileName;
                    var fullName = string.Empty;
                    var newFile = new FileInfo(file.LocalFileName);

                    if (fileName.Contains("\""))
                        newName =  fileName.Substring(1, fileName.Length - 2);

                    fullName = Path.Combine(root.ToString(), newName);

                    newFile.MoveTo(fullName);
                    // get id from the first file
                    if (clientSurveyId == 0)
                    {
                        clientSurveyId = GetId(newName);
                    }
                    if (clientSurveyId>0)
                    {
                        Image image = new Image() { ClientId = 1, path = fileName, ClientSurveyId = clientSurveyId }; 
                        db.Images.Add(image);
                        newFiles.Add(newName);
                    }
                }
                //save image file name to image table in the database
                db.SaveChanges();
                return Request.CreateResponse(HttpStatusCode.OK, newFiles.Count + " file(s) uploaded.");
            }
            catch (System.Exception e)
            {
                CommonLib.ExceptionUtility.LogException(CommonLib.ExceptionUtility.Application.General, e, "Post Images");
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
            }
        }
开发者ID:KavMuthu,项目名称:home-app,代码行数:60,代码来源:ImageUploadController.cs

示例7: PluginFileManager

        public PluginFileManager( Guid abcPluginGuid, PluginType abcPluginType, string pluginPath = null )
        {
            // Plug-in paths setup.
            _pluginDownloadPath = RemotePluginPath + abcPluginGuid + PluginExtention;
            _pluginTempPath = Path.Combine( GetPluginDirectory( abcPluginType ), TempDirectory, abcPluginGuid.ToString() ) + GetPluginExtention( abcPluginType );
            _pluginPath = pluginPath ?? Path.Combine( GetPluginDirectory( abcPluginType ), abcPluginGuid.ToString() ) + GetPluginExtention( abcPluginType );

            _pluginfileInfo = new FileInfo( _pluginTempPath );

            if ( !Directory.Exists( _pluginTempPath ) )
            {
                Directory.CreateDirectory( _pluginfileInfo.DirectoryName );
            }

            _webClient = new WebClient();
            _webClient.DownloadFileCompleted += ( sender, args ) =>
            {
                // When download is completed and performed properly move to final destination, otherwise delete.
                if ( args.Error == null && !args.Cancelled )
                {
                    _pluginfileInfo.MoveTo( Path.Combine( _pluginfileInfo.Directory.Parent.FullName, _pluginfileInfo.Name ) );
                }
                else
                {
                    File.Delete( _pluginTempPath );
                }
            };
        }
开发者ID:Whathecode,项目名称:ABC,代码行数:28,代码来源:PluginFileManager.cs

示例8: MoveFileTo

        private static void MoveFileTo(FileInfo srcFileInfo, String destDir)
        {
            string createDate = srcFileInfo.LastWriteTime.ToString("yyyyMM");
            string ext = srcFileInfo.Extension;
            string imagesExt = "jpg|jpeg|png";
            string vedioExt = "mp4|3gp";

            string path = destDir + @"\";
            if (Regex.IsMatch(ext, imagesExt, RegexOptions.IgnoreCase))
            {
                path += @"照片\" + createDate + @"\";
            }
            else if (Regex.IsMatch(ext, vedioExt, RegexOptions.IgnoreCase))
            {
                path += @"视频\" + createDate + @"\";
            }
            else
            {
                path += @"其他\" + createDate + @"\";
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            srcFileInfo.MoveTo(path + srcFileInfo.Name);
        }
开发者ID:xianrendzw,项目名称:MobilePhoto,代码行数:28,代码来源:Categoryer.cs

示例9: MoveToNextAvailableFilename

 static void MoveToNextAvailableFilename(FileInfo file, string directory, string filename, string extension)
 {
     var newFullName = Path.Combine(directory, string.Format("{0}{1}", filename, extension));
     int i = 0;
     while (i < int.MaxValue)
     {
         if (!File.Exists(newFullName))
         {
             if (!Directory.Exists(directory))
             {
                 Console.WriteLine("Creating folder {0}", directory);
                 Directory.CreateDirectory(directory);
             }
             Console.WriteLine("Moving {0} to {1}", file.FullName, newFullName);
             file.MoveTo(newFullName);
             return;
         }
         else
         {
             Console.WriteLine("Found a file with name {0}; Comparing", newFullName);
             if (FileUtils.FileCompare(file, new FileInfo(newFullName)))
             {
                 Console.WriteLine("Deleting duplicate file {0}", file.FullName);
                 file.Delete();
                 return;
             }
             newFullName = Path.Combine(directory,
                 string.Format("{0}_{1}{2}", filename, ++i, extension));
         }
     }
 }
开发者ID:dredix,项目名称:photorganiser,代码行数:31,代码来源:Program.cs

示例10: ConvertFile

        /// <summary>
        /// Converts the file
        /// </summary>
        /// <param name="fileName">The path to the file which should become converted</param>
        /// <param name="newFileName">The name of the new file WITHOUT extension</param>
        /// <param name="bitrate">The audio bitrate</param>
        /// <param name="format"></param>
        public static async Task ConvertFile(string fileName, string newFileName, AudioBitrate bitrate, AudioFormat format)
        {
            var fileToConvert = new FileInfo(fileName);

            var p = new Process
            {
                StartInfo =
                {
                    CreateNoWindow = true,
                    FileName = HurricaneSettings.Paths.FFmpegPath,
                    Arguments = GetParameter(fileName, newFileName, bitrate, format),
                    UseShellExecute = false
                }
            };

            p.Start();
            await Task.Run(() => p.WaitForExit());
            var newFile = new FileInfo(newFileName);

            if (!newFile.Exists || newFile.Length == 0)
            {
                if (newFile.Exists) newFile.Delete();
                fileToConvert.MoveTo(newFileName); //If the convert failed, we just use the "old" file
            }

            fileToConvert.Delete();
        }
开发者ID:WELL-E,项目名称:Hurricane,代码行数:34,代码来源:ffmpeg.cs

示例11: moveFiles

        // Moves file from source path to destination
        // path. If it is less than 24 hours old
        // Returns Number of Files Transfered.
        public int moveFiles(string source, string destination)
        {
            int counter = 0;
            source = Path.GetFullPath(source);
            destination = Path.GetFullPath(destination);
            if (Directory.Exists(source))
            {
                string[] files = Directory.GetFiles(source);
                foreach(string s in files)
                {

                    string fileName = (s);
                    FileInfo filePath = new FileInfo(fileName);
                    if (isNewFile(fileName))
                    {
                        string destinationFile = Path.Combine(destination, (Path.GetFileName(fileName)));
                        if (File.Exists(destinationFile))
                        {
                            File.Delete(destinationFile);
                            destinationFile = Path.Combine(destination, (Path.GetFileName(fileName)));
                        }

                        filePath.MoveTo(destinationFile);
                        counter++;
                    }
                }
            }
            return counter;
        }
开发者ID:aaronlinc,项目名称:dailyFileTransfer,代码行数:32,代码来源:Program.cs

示例12: DoWork

 public static void DoWork(string fullName, bool lookup)
 {
     SourceFile src = new SourceFile(fullName, lookup);
     NewFile nf = new NewFile();
     nf.LoadInfo(src);
     if (src.Series != null && src.Episode != null && !lookup)
     {
         string strEpisode = (src.Episode.Episode < 10) ? "0" + src.Episode.Episode.ToString() : src.Episode.Episode.ToString();
         string strSeason = src.Episode.Season.ToString();
         if (MessageBox.Show(string.Format("Old name: '{0}'\nNew name: '{1} - {2}{3} - {4}'\nIs this correct?", fullName, src.Series.Name, strSeason, strEpisode, src.Episode.Name), "Found a match!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             FileInfo oldFile = new FileInfo(fullName);
             while (true)
             {
                 Rename rn = new Rename(string.Format(@"{0} - {1}{2} - {3}", src.Series.Name, strSeason, strEpisode, src.Episode.Name));
                 DialogResult res = rn.ShowDialog();
                 if (res == DialogResult.OK)
                 {
                     if (File.Exists(oldFile.DirectoryName + "\\" + rn.NewFile + oldFile.Extension))
                     {
                         if (MessageBox.Show(string.Format("The file: {0} already exists! Try another name.", rn.NewFile), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Cancel)
                             break;
                     }
                     else
                     {
                         string newName = oldFile.DirectoryName + "\\" + rn.NewFile + oldFile.Extension;
                         if (File.Exists(oldFile.FullName))
                         {
                             int count = 0;
                             while (true)
                             {
                                 try
                                 {
                                     oldFile.MoveTo(newName);
                                     break;
                                 }
                                 catch
                                 {
                                     Thread.Sleep(1000);
                                     count++;
                                     if (count == 60)
                                     {
                                         MessageBox.Show(string.Format("File cannot be moved after {0} attempts! Program will now terminate.", count), "File cannot be moved!", MessageBoxButtons.OK);
                                         break;
                                     }
                                 }
                             }
                         }
                         else
                             MessageBox.Show("Original file cannot be found! Program will now terminate.", "File not found!", MessageBoxButtons.OK);
                         return;
                     }
                 }
                 else if (res == DialogResult.Cancel)
                     break;
             }
         }
     }
     nf.ShowDialog();
 }
开发者ID:wettsten,项目名称:EpiFlow,代码行数:60,代码来源:SearchForm.cs

示例13: CreateActivity

        /// <summary>
        /// 新建活动
        /// </summary>
        /// <param name="name">活动名称</param>
        /// <param name="poster">宣传海报</param>
        /// <param name="begintime">开始时间</param>
        /// <param name="endtime">结束时间</param>
        /// <param name="address">地址</param>
        /// <param name="ownerid">负责人(联系人)</param>
        /// <param name="remark">描述</param>
        /// <param name="userid">创建人</param>
        /// <param name="agentid">代理商ID</param>
        /// <param name="clientid">客户端ID</param>
        /// <returns></returns>
        public static string CreateActivity(string name, string poster, string begintime, string endtime, string address, string ownerid, string memberid, string remark, string userid, string agentid, string clientid)
        {
            string activityid = Guid.NewGuid().ToString();

            if (!string.IsNullOrEmpty(poster))
            {
                if (poster.IndexOf("?") > 0)
                {
                    poster = poster.Substring(0, poster.IndexOf("?"));
                }
                FileInfo file = new FileInfo(HttpContext.Current.Server.MapPath(poster));
                poster = FilePath + file.Name;
                if (file.Exists)
                {
                    file.MoveTo(HttpContext.Current.Server.MapPath(poster));
                }
            }
            bool bl = ActivityDAL.BaseProvider.CreateActivity(activityid, name, poster, begintime, endtime, address, ownerid,memberid, remark, userid, agentid, clientid);
            if (!bl)
            {
                return "";
            }
            else
            {
                //日志
                LogBusiness.AddActionLog(CloudSalesEnum.EnumSystemType.Client, CloudSalesEnum.EnumLogObjectType.Activity, EnumLogType.Create, "", userid, agentid, clientid);
            }
            return activityid;
        }
开发者ID:GitMr,项目名称:YXERP,代码行数:43,代码来源:ActivityBusiness.cs

示例14: Main

 private static int Main(string[] args)
 {
     if (args.Length < 3)
     {
         Console.Out.WriteLine("Versioning [Msi Package] [Dll] [New Filename]");
         return 0;
     }
     FileInfo info = new FileInfo(args[0]);
     FileInfo file = new FileInfo(args[1]);
     string format = args[2];
     if (!info.Exists)
     {
         Console.Out.WriteLine("Unable to find msi package: " + args[0]);
     }
     if (!file.Exists)
     {
         Console.Out.WriteLine("Unable to find dll" + args[1]);
     }
     if (!info.Exists || !file.Exists)
     {
         return 8;
     }
     string version = GetVersion(file);
     string destFileName = string.Format(format, version);
     info.MoveTo(destFileName);
     return 0;
 }
开发者ID:pettingj,项目名称:Versioning,代码行数:27,代码来源:Program.cs

示例15: ArchiveNormal

        /// <summary>
        /// The normal PDF archival method.
        /// </summary>
        /// <param name="pdfFile">The PDF file.</param>
        /// <param name="archiveDirectory">The archive directory.</param>
        public static void ArchiveNormal(FileInfo pdfFile, string archiveDirectory)
        {
            // Create a new subdirectory in the archive directory
            // This is based on the date of the report being archived
            DirectoryInfo di = new DirectoryInfo(archiveDirectory);
            string archiveFileName = pdfFile.Name;
            string newSubFolder = ParseFolderName(archiveFileName);
            try
            {
                di.CreateSubdirectory(newSubFolder);
            }
            catch (Exception ex)
            {
                // The folder already exists so don't create it
            }

            // Create destination path
            string destFullPath = archiveDirectory + "\\" + newSubFolder + "\\" + pdfFile.Name;

            // Move the file to the archive directory
            try
            {
                pdfFile.MoveTo(destFullPath);
            }
            catch (Exception ex)
            {
                // Unable to move the PDF to the archive
            }
        }
开发者ID:RonFields72,项目名称:EmailACHReportsToVendors,代码行数:34,代码来源:FileHelper.cs


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