Created
August 6, 2020 07:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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