Manually I would do this as per below but how to enter it into the user command dialog in TC?
Code: Select all
C:\> ren filename.txt filename_%date%.txt
Moderators: white, Hacker, petermad, Stefan2
Code: Select all
C:\> ren filename.txt filename_%date%.txt
Code: Select all
TOTALCMD#BAR#DATA
%COMSPEC% /C
ren %N "%O_%%date%%.%E"
WCMICONS.DLL,63
Add date to the filename
1
-1
To make the button:
1. Mark the text in the box here above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctrl+C).
3. Right click on TC's buttonbar and choose "Paste".
This solution has the disadvantage that the sort order will be wrong if a file with different dates exists.petermad wrote: ↑2020-07-28, 12:07 UTC 2Pocus
You can use this button:Code: Select all
TOTALCMD#BAR#DATA %COMSPEC% /C ren %N "%O_%%date%%.%E" WCMICONS.DLL,63 Add date to the filename 1 -1
To make the button:
1. Mark the text in the box here above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctrl+C).
3. Right click on TC's buttonbar and choose "Paste".
Pocus wrote: ↑2020-07-28, 11:25 UTC Could someone please help me with a user command to rename a file from filename.txt to filename_date.txt?
Manually I would do this as per below but how to enter it into the user command dialog in TC?Code: Select all
C:\> ren filename.txt filename_%date%.txt
Code: Select all
Command: PowerShell
Parameters: Get-Content '%WF'|ForEach{$FileName=(GCI $_);Rename-Item -Path $FileName -NewName $('{0}_{1}{2}' -f $FileName.BaseName,([datetime]::now).tostring('yyyy-MM-dd HHmmss'),$FileName.Extension)}
Start path:
Icon file: PowerShell
Tooltip: Rename with current timestamp: Base_Time.Ext
Code: Select all
TOTALCMD#BAR#DATA
PowerShell
Get-Content '%WF'|ForEach{$FileName=(GCI $_);Rename-Item -Path $FileName -NewName $('{0}_{1}{2}' -f $FileName.BaseName,([datetime]::now).tostring('yyyy-MM-dd HHmmss'),$FileName.Extension)}
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Rename with current timestamp: Base_Time.Ext
1
-1
Code: Select all
TOTALCMD#BAR#DATA
PowerShell
Get-Content '%WF'|ForEach{$FileName=(GCI $_);Rename-Item -Path $FileName -NewName $('{1}_{0}{2}' -f $FileName.BaseName,(($FileName.LastWriteTime).tostring('yyyy-MM-dd HHmm')),$FileName.Extension)} #CreationTime #LastAccessTime
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Rename with LastWriteTime: Time_Base.Ext
1
-1
Horst.Epp wrote: ↑2020-07-28, 12:40 UTCThis solution has the disadvantage that the sort order will be wrong if a file with different dates exists.petermad wrote: ↑2020-07-28, 12:07 UTC 2Pocus
You can use this button:Code: Select all
TOTALCMD#BAR#DATA %COMSPEC% /C ren %N "%O_%%date%%.%E" WCMICONS.DLL,63 Add date to the filename 1 -1
To make the button:
1. Mark the text in the box here above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctrl+C).
3. Right click on TC's buttonbar and choose "Paste".
Date should be ([YMD]) for correct sorting.
Code: Select all
TOTALCMD#BAR#DATA
%COMSPEC% /C
ren %N "%O_%%date:~6,4%%-%%date:~3,2%%-%%date:~0,2%%.%E"
WCMICONS.DLL,63
Add date to the filename
1
-1
Code: Select all
[em_addatetofilename]
cmd=%COMSPEC% /C
param=ren %N "%O_%%date:~6,4%%-%%date:~3,2%%-%%date:~0,2%%.%E"
iconic=1
... or a [ and ] ...
Code: Select all
gc .\filelist.txt | % { gi -LiteralPath $_ } | % { ren -literalpath $_ ($_.Basename + $_.LastWriteTime.Tostring(' yyyy-MM-dd') + $_.extension) -f }
Not tested, but I suspect GCI (Get-ChildItem) goes horribly wrong when you selected a foldername in TC.
MVV wrote: ↑2020-07-29, 13:13 UTC Well, as I understand, -LiteralPath is for wildcards, and you will not get ones from TC button. But it will not prevent PowerShell from expanding $vars in double-quoted string or confusing due to apostrophes in a single-quoted string. And, if you use $_ in a pipe, you will still need to somehow quote filelist path at the beginning of that pipe. Though, it may be easier since TC usually creates filelists in %TEMP% (of course if your %USERNAME% doesn't contain these problematic characters).
What could really help is supporting both inplace script and arguments in PowerShell command line but there is no such support.
Code: Select all
PS T:\rename-list> Out-File '.\some$var.txt'
PS T:\rename-list> $var = "foo"
PS T:\rename-list> (gi '.\some$var.txt').FullName > thislist.txt
PS T:\rename-list> gc .\thislist.txt
T:\rename-list\some$var.txt
PS T:\rename-list> gc .\thislist.txt | % { gi -LiteralPath $_ }
Directory: T:\rename-list
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 29-7-2020 16:02 2 some$var.txt
PS T:\rename-list> gc .\thislist.txt | % { gi -LiteralPath $_ } | % { ren -literalpath $_ ($_.Basename + "bar" + $_.extension) -f }
PS T:\rename-list> ls
Directory: T:\rename-list
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 29-7-2020 16:02 2 some$varbar.txt
-a---- 29-7-2020 16:03 60 thislist.txt
PS T:\rename-list>
Huu thx
Code: Select all
TOTALCMD#BAR#DATA
PowerShell
GC '%F'|%%{$F=(GI -LiteralPath $_);RNI -LiteralPath $F $('{1}_{0}{2}' -f $F.BaseName,(($F.LastWriteTime).tostring('yyyy-MM-dd HHmmss')),$F.Extension)}
C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Rename with LastWriteTime: Time_Base.Ext
1
-1