Copy files and change name with PowerShell
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgteKjuWqVals2Kk7oUYxIfyaQHLSE7U9tzhyphenhyphenxwgHLpfQuMWZ3ADs78xlL6fkJfV-JRH6LwYTUP2V0t1C2NBnsc7o9qrzK4k_bb6Ot_UCoux5T214NqyItWHVai_6wH-UbmewzprVuT_hJP/s1600/copy-typing.jpg)
A friend of mine asked if I could copy files from one folder to another and rename them according to the following format
YYYYMMDDHHMMSS.ext
here source code:
cls
$source="C: ext72source"
$destination="C: ext72destination"
set-location $source
$files=get-childitem -Recurse
foreach ($file in $files)
{
if (!$file.PsIsContainer)
{
$newName=$destination+""+[string]$file.LastWriteTime.Year +
[string]$file.LastWriteTime.Month +
[string]$file.LastWriteTime.Month +
[string]$file.LastWriteTime.Day +
[string]$file.LastWriteTime.Hour +
[string]$file.LastWriteTime.Minute +
[string]$file.LastWriteTime.Second +
[string]$file.Extension
Copy-Item $file.FullName $newName
}
}
Then change source and destination variable in the script.
alternative link download