作者: bongbong3481 時間: 2016-9-30 19:16 標題: 點樣用batch/vbs將FOLDER 入邊既所有FILE變成檔名後加日期?
有個FOLDER, 入邊有好多個唔同名既FILE: File1, FileA.......
有沒辦法用dos batch or vbs 將 所有FILE 名改成 File1_YYYYMMDD, FileA_YYYYMMDD.......
因為FILE 數量比較多, 人手整, 整好奈
作者: q_p 時間: 2016-10-1 12:54
回覆 1# bongbong3481
StampMe.cmd
作者: bongbong3481 時間: 2016-10-1 19:22
回覆 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%"
作者: 狂蜂一號 時間: 2016-10-1 23:50
回覆 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!!!
作者: bongbong3481 時間: 2016-10-2 12:00
回覆 4# 狂蜂一號
呢位仁兄, 差少少, 日期變左系檔案類型後, 例如 test.txt==> test.txt_20161002,
我最後搵左個方法(主要系檔案類型只有一種), 我用replace 將“.txt” 變成"", 加左日期後, 再加番".txt"上去
作者: 狂蜂一號 時間: 2016-10-2 23:34
回覆 5# bongbong3481
其實好多 file manager 都可以一下攪掂格。
作者: bongbong3481 時間: 2016-10-3 08:18
回覆 6# 狂蜂一號
因為系公司野黎,安裝吾到軟件,所以要自己寫dos batch/vbs
作者: 狂蜂一號 時間: 2016-10-3 23:03
明白晒。
作者: 251523294 時間: 2016-10-5 09:45
本帖最後由 251523294 於 2016-10-5 09:56 編輯
PowerShell
For Example:
File Local at C:\Users\Public\Pictures\Sample Pictures
- Get-ChildItem 'C:\Users\Public\Pictures\Sample Pictures\*.jpg' -Recurse | % {
- # $_.name is the name with extension but since you want to
- # specify .jpg I used the basename
- $name = $_.basename
- $creationtime = get-date $_.creationtime -format "dd-MM-yyyy-HH-mm"
- $newname = $creationtime + '_' + $name + '.jpg'
- Rename-Item $_ -newname $newname
- }
作者: bongbong3481 時間: 2016-10-5 18:43
回覆 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
作者: 251523294 時間: 2016-10-6 10:46
回覆 251523294
請教一下, powershell 唔識, 我上網睇, 先將你段code變成ps1 檔, right click edit ...
bongbong3481 發表於 2016-10-5 18:43
用著 powershell ISE 先
作者: bongbong3481 時間: 2016-10-6 18:33
本帖最後由 bongbong3481 於 2016-10-6 18:35 編輯
回覆 11# 251523294
我好似用緊ISE
[attach]1928681[/attach]
作者: q_p 時間: 2016-10-6 20:53
本帖最後由 q_p 於 2016-10-6 20:56 編輯
回覆 10# bongbong3481
try this in PowerShell
- Set-ExecutionPolicy Unrestricted
- powershell -ExecutionPolicy ByPass -File script.ps1
作者: bongbong3481 時間: 2016-10-6 22:43
回覆 13# q_p
得喇

