简体   繁体   中英

How to rename all file names under a folder to add modified date as prefix in Windows

I have a folder C:\\Documents

I have over 100 files under the folder.

file1.docx 
blah.docx
.
.

I would like to rename all files as below where modified_date is from the LastWriteTime timestamp on the file:

A_{modified_date}_filename note that that must be ddMMyyyy format.

Example output:

A_01012015_file1.docx
A_20122014_blah.docx

I can write a simple console application to achieve this. But Just wondering if there is an existing tool built-in or by using Powershell?

Thanks

Did you mean include the last write date in the file name like so:

Get-ChildItem | 
  Rename-Item -NewName {'A_' + $_.LastWriteTime.ToString('ddMMyyyy') + $_.name}

By using @Dave answer.

I have figured out how to add any prefix at the end of each individual file as well.

Get-ChildItem | 
Rename-Item -NewName {$_.BaseName+'_'+$_.LastWriteTime.ToString('ddMMyyyy')+$_.Extension}

Note that BaseName is supported in PS v2 and above.

I hope it helps someone else out there.

BaseName is supported in PS v2 and above.

cmd /c for /F "tokens=1,2,3,4 delims=/. " %a in ('date/T') do forfiles /p <PATH> /m *.xlsx /c "cmd /c ren @file %c%b%a_@file"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM