问题
Good evening everyone. I have been able to change date created attribute of a file using the following command $(Get-Item test1.html).CreationTime=$(Get-Date "11/24/2010 06:00 am")
My problem is that I have 10000 files that need to have this done based on a csv file. CSV has two columns file name or and file created date. CSV and files are in same folder. How can I rename the files based on the corresponding date in column 2
eg.
1.pdf 2010/12/12
2.pdf 2011/13/01
3.pdf 1989/12/12
etc
Thanks in advance. Perhaps I can use powershell to do this I can use excel to create 3rd column to get the following. Copy and paste in powershell window did not work
$(Get-Item 1.pdf).CreationTime=$(Get-Date "11/24/2010 06:00 am")
$(Get-Item 2.pdf).CreationTime=$(Get-Date "11/24/2009 06:00 am")
but then how do I run this file in powershell.
回答1:
assuming your csv file has 2 headers : FileName & FileCreationTIme
Import-Csv -Path 'pathtoyourcsvfile' |
ForEach-Object { (Get-Item $_.filename).CreationTime = (Get-date $_.filecreationTime) }
回答2:
you may use dir
, findstr
and the for
loop
dir /T:C *.pdf>tmp.txt & findstr " PM " tmp.txt >files.txt & findstr " AM " tmp.txt >>files.txt & del tmp.txt
for /F "tokens=1,2,3,4,5 delims= " %%A in (files.txt) do (echo %%E %%A %%B %%C) & if exist files.txt del files.txt
来源:https://stackoverflow.com/questions/36347191/need-to-change-file-created-date-based-on-csv