Hello,
I have one script ready for power shell which can read .PDF file and according to its file format it goes to particular year and month folder,
Now I have one other file which require sorting and they are .mp3 file but file format is different than PDF ,
Here is the Example of PDF file
CC_F123486_20100617104742.pdf
last part is 2010 year, 06 is month,
by given script I can create Year\ Month folders and accordingly I can move files to year and month
but what if I would like to sort files as below according to date and this time file date is something like this
\\YYYY\MONTH\Date( DD-MM-YY\Telephone number_yymmdd_hhmmss.mp3
Example :
\\2012\November\08-Nov-12\6133477680_121108_160516.mp3
now, how Would I read middle part of date and put accordingly in to particular folder? what should I require to add /modify in current script?
$MonthName = @("January", "February", "March", "April", "May", "June", "July", "August", "September", "October","November", "December")
# create Destination Folder's
2007..2013 | ForEach-Object
{
New-Item -ItemType Directory "c:\Test\Destination\$_"
Set-Location c:\Test\Destination\$_
1..12 | ForEach-Object
{
New-Item -ItemType Directory "$_-$($MonthName[$_-1])"
}
}
# read the source Files
$SourceFiles = Get-ChildItem C:\test | Where-Object {!($_.PsisContainer) -and $_.extension -eq ".mp3"} | Select-Object -ExpandProperty Name
# move the files
foreach ($SourceFile in $SourceFiles)
{
$datestr = $SourceFile.split("_")[2]
$year = $datestr.Substring(0,4)
[int]$month = $datestr.Substring(4,2)
Move-Item c:\test\$SourceFile C:\Test\Destination\$year\$month-$($MonthName[$month-1])
}
Can anyone Help Please?
P Dave