Hello friends,
I am trying to organise all the files in a big folder, now it has a lot of files that need to be organized.
I got the idea from here for a powershell script to help my poor hands.
#http://stackoverflow.com/questions/6477612/organizing-files-by-type
The script will look for files that have a keyword in the file name
Example if file name contains Apple or House move to the folder "home"
{ $_.FileName -match '(Car|House)'} { "home" }
Now I have got stuck for hours and hours :( and well i need your great help please
=============================
function get-destbytype($FileName)
{
switch ($FileName)
{
{ $_.FileName -match '(jpg|gif)'} { "images" }
{ $_.FileName -match '(Car |House)'} { "home" }
default {"$FileName" }
}
}
$Oldfolder = "C:\Users\PW\Desktop\a\"
$org = "$nas\Users\PW\Desktop\b"
ls $Oldfolder/* | ? {!$_.PSIsContainer} | %{
$dest = "$($org)\$(get-destbytype $_.FileName)"
if (! (Test-Path -path $dest ) )
{
write-host "creating $dest"
new-item $dest -type directory
}
mv -path $_ -destination $dest
}
===========================
The script only copies the files as is to the destination folder.
It does not create the folders :(
please help
thank you very much for your expert guidance
pw