LightninBolt74
LightninBolt74

Reputation: 213

How to modify the date-created attribute for multiple files using .csv data?

I am unsure on how to word my problem as it's not something I am familiar with, but Powershell is probably what I'm need to use.

I saw this: need to change file created date based on csv (4 years ago)

and would like to know how I can apply this to my problem.

I have many .mp4 files in the folder videos that have incorrect date-created attributes.

I also have a .csv file that lists the all the files in videos in chronological order (using the respective filenames).

The first file starts at 15 Nov 2019, and each successive video is created 1 day after the prior.

How can powershell help me modify the date-created attribute of every file using the rows of the files in the .csv file.

CSV FILE: contains the filenames IN CHRONOLOGICAL ORDER

video1
video2
video3
...

videos Folder:

name    date created

video1  dd/mm/yyyy
video2  dd/mm/yyyy
video3  dd/mm/yyyy
...     ...        <---- dates are incorrect

What I would like:

name    date created

video1  15/11/2019
video2  16/11/2019
video3  17/11/2019
...     ...        <---- dates are in chronological order according to .csv file

Thanks for your help!

Upvotes: 0

Views: 1353

Answers (2)

LightninBolt74
LightninBolt74

Reputation: 213

@Doug Maurer provided an incomplete answer (did not work) so here is the working solution:

$csvfile = 'path/to/csvfile.csv'
$startdate = [datetime]::ParseExact('15/11/2019','dd/MM/yyyy',$null) 

Set-Location 'path/to/folder'

Import-Csv $csvfile | ForEach-Object {

    #set creationtime
    (Get-Item $_.filename).CreationTime = $startdate

    #increase date by one day
    $startdate = $startdate.AddDays(1)
}

Upvotes: 0

Doug Maurer
Doug Maurer

Reputation: 8868

Assuming that:

A) all your files are in the same folder OR B) you have the full paths in your CSV

AND C) your csv files header is called filename

$csvfile = 'Path\to\csvfile.csv'
$startdate = Get-Date 11/15/2019

Set-Location Path\to\videofiles

Import-Csv $csvfile | ForEach-Object {

    #set creationtime
    (Get-Item $_.filename).CreationTime = $startdate

    #increase date by one day
    $startdate = $startdate.AddDays(1)
}

Upvotes: 1

Related Questions