亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

追加時間戳并移動文件 C#

追加時間戳并移動文件 C#

PHP
慕尼黑的夜晚無繁華 2024-01-20 22:23:46
我正在嘗試通過以下方式將時間戳附加到名稱來移動和重命名文件:private void MoveFile(string from, string to, string filename) {     File.Move(from, System.IO.Path.Combine(to, filename + DateTime.Now.ToString().Replace(":", "-"))); }我這樣稱呼它:MoveFile(currentPath, outputFolderPath, System.IO.Path.GetFileName(currentPath));這會導致以下異常:引發異常:“System.IO.DirectoryNotFoundException” mscoorlib.dll。如果我刪除時間戳的附加,它就會起作用。為什么會出現此錯誤?
查看完整描述

1 回答

?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

如果你像這樣使用你的函數:


MoveFile(@"C:\Users\Admin\Desktop\IMG_5628.png", @"C:\Users\Admin\Desktop", "IMG_5628.png");

那么你的路徑將如下所示:


C:\Users\Admin\Desktop\IMG_5628.png30.09.2019 2-33-34

按如下方式更改函數:


    MoveFile(@"C:\Users\Admin\Desktop\IMG_5628.png", @"C:\Users\Admin\Desktop", "IMG_5628.png");


    private void MoveFile(string from, string to, string filename)

    {

        File.Move(from, System.IO.Path.Combine(to, System.IO.Path.GetFileNameWithoutExtension(filename) + DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss") + System.IO.Path.GetExtension(filename)));

    }

并且文件的路徑將是有效的。


C:\Users\Admin\Desktop\IMG_56282019-30-9--02-39-03.png


查看完整回答
反對 回復 2024-01-20
  • 1 回答
  • 0 關注
  • 224 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號