點樣用batch/vbs將FOLDER 入邊既所有FILE變成檔名後加日期?

有個FOLDER, 入邊有好多個唔同名既FILE: File1, FileA.......

有沒辦法用dos batch or vbs 將 所有FILE 名改成 File1_YYYYMMDD, FileA_YYYYMMDD.......

因為FILE 數量比較多, 人手整, 整好奈

回覆 1# bongbong3481
StampMe.cmd

TOP

回覆 2# q_p

請問系唔系, COPY 段CODE SAVE 成BAT 檔 就得?  我試過唔多得

  @ECHO off
  SETLOCAL
  IF [%1] NEQ [] goto s_start

  :: Author - Simon Sheppard, Nov 2014
  :: Tested for Windows XP Pro or greater
  Echo StampMe.cmd
  Echo Rename a file with the DATE/Time
  Echo:
  Echo Syntax
  Echo    STAMPME TestFile.txt
  Echo:
  Echo    STAMPME "Test File.txt"
  Echo:
  Echo    STAMPME "c:\docs\Test File.txt"
  Echo:
  Echo    Will rename the file in the format "Test File-2014-12-30@16-55-01.txt"
  Echo:
  Echo    In a batch file use CALL STAMPME ...
  GOTO :eof
  
  :s_start
  Set _file=%~n1%
  Set _pathname=%~f1%
  Set _ext=%~x1%
  
  :: Get the date/time
  FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO Set _DTS=%%a
  Set _datetime=%_DTS:~0,4%-%_DTS:~4,2%-%_DTS:~6,2%@%_DTS:~8,2%-%_DTS:~10,2%-%_DTS:~12,2%

  Echo   Year-MM-Day@HR-Min-Sec
  Echo   %_datetime%
  
  :: Rename the file
  REN "%_pathname%" "%_file%-%_datetime%%_ext%"

TOP

回覆 1# bongbong3481

For your reference
------------------

[from Excel VBA Help - not test]

Sub RenameFiles()
   Dim fs, f, f1, fc
   Dim MyFolder As String, MyDate As String
   MyFolder = "E:\Path\Folder\"
   Set fs = CreateObject("Scripting.FileSystemObject")
   Set f = fs.GetFolder(MyFolder)
   Set fc = f.Files
   MyDate = Format(Date, "yyyymmdd")
   For Each f1 In fc
      f1.Name = f1.Name & "_" & MyDate 'handle your String here!
   Next
End Sub

*** Backup your files first!!!

TOP

回覆 4# 狂蜂一號

呢位仁兄, 差少少, 日期變左系檔案類型後, 例如 test.txt==> test.txt_20161002,

我最後搵左個方法(主要系檔案類型只有一種), 我用replace 將“.txt” 變成"",  加左日期後, 再加番".txt"上去

TOP

回覆 5# bongbong3481

其實好多 file manager 都可以一下攪掂格。

TOP

回覆 6# 狂蜂一號

因為系公司野黎,安裝吾到軟件,所以要自己寫dos batch/vbs

TOP

回覆  狂蜂一號

因為系公司野黎,安裝吾到軟件,所以要自己寫dos batch/vbs ...
bongbong3481 發表於 2016-10-3 08:18


明白晒。

TOP

本帖最後由 251523294 於 2016-10-5 09:56 編輯

PowerShell

For Example:
File Local at C:\Users\Public\Pictures\Sample Pictures
  1. Get-ChildItem 'C:\Users\Public\Pictures\Sample Pictures\*.jpg' -Recurse |  % {

  2. # $_.name is the name with extension but since you want to
  3. # specify .jpg I used the basename
  4. $name = $_.basename

  5. $creationtime = get-date $_.creationtime -format "dd-MM-yyyy-HH-mm"
  6. $newname = $creationtime + '_' + $name + '.jpg'
  7. Rename-Item $_ -newname $newname
  8. }
複製代碼

TOP

回覆 9# 251523294

請教一下, powershell 唔識, 我上網睇, 先將你段code變成ps1 檔, right click edit ,  跑左個Windows PowerShell , 我CLICK “RUB SCRIPT”, 出左以下ERROR, 請問邊到錯左?  (好似系統禁止)

PS C:\Users\family\Desktop> C:\Users\family\Desktop\test.ps1
File C:\Users\family\Desktop\test.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:0 char:0

TOP