Skip to content

Instantly share code, notes, and snippets.

@gioxx
Created August 6, 2020 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gioxx/9fed53c3607efe2be086ae3c1fff53ca to your computer and use it in GitHub Desktop.
Save gioxx/9fed53c3607efe2be086ae3c1fff53ca to your computer and use it in GitHub Desktop.
Funzione di riorganizzazione dei file in base al nome del documento. Se il nome del file contiene nelle prime posizioni l'anno e il mese io posso utilizzarlo per riorganizzare tutto in cartella, vedi l'articolo sul blog: https://wp.me/pdQ5q-dlE
# Credits: https://stackoverflow.com/a/52605580/2220346
function DataReorg {
$files = Get-ChildItem $args[0] -Recurse | where {!$_.PsIsContainer}
$targetPath = $args[1]
foreach ($file in $files)
{
$bn = $file.basename.ToString()
$year = $bn.substring(0,4)
$month = $bn.substring(4,2)
$Directory = $targetPath + "\" + $year + "\" + $month
if (!(Test-Path $Directory)) { New-Item $directory -type directory }
$file | Move-Item -Destination $Directory
}
}
DataReorg 'C:\Folder1\*.csv' 'C:\Folder1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment