Solved

I need to move some Folders

Posted on 2014-03-04
5
363 Views
Last Modified: 2014-03-22
Hi,

How can I all at once move the folders (+ files in the folders) in the "From" folder, to the "To" folder.

02 is the month
2014 is the year
These values will change every month and year.

I am open to any technology/method, and a commercial solution is OK. - Any suggestions would be grateful!!

From: W:\WOW HITS - 02-2014
To: W:\Vid\WOW HITS\WOW HITS 2014\

From: W:\HOT MOVIE CLASSICS - 02-2014
To: W:\Vid\HOT MOVIE CLASSICS\HOT MOVIE CLASSICS 2014\

From: W:\AMBIENT VIDEO 02-14
To: W:\Vid\AMBIENT VIDEO\AMBIENT VIDEO 2014\
0
Comment
Question by:Computer Guy
  • 3
5 Comments
 
LVL 52

Expert Comment

by:Bill Prew
ID: 39903698
Do you want to specify the current month and year as a parameter, or let the script pick up the current system date?

~bp
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 39903701
And, was this a typo or does this one really only use a two digit year?

From: W:\AMBIENT VIDEO 02-14

or should it match the others like:

From: W:\AMBIENT VIDEO - 02-2014

~bp
0
 
LVL 3

Author Comment

by:Computer Guy
ID: 39903765
Haha. Typo. Year is suppose to be 4 digits and month 2. Good eye!!
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 39903783
Okay, here is a starting point assuming a typo in the examples, and assuming you hard code the month and year into the script.  This can easily be adjusted to either take them as a command line parameter, or get them from the current date, or maybe a combo.

Save as a BAT file, adjust the paths as needed, and do some testing...

@echo off
setlocal EnableDelayedExpansion

set MM=02
set YYYY=2014

REM Define folder locations (no trailing "\")
REM set BaseDir=W:
REM set DestDir=W:\Vid
set Folders="WOW HITS","HOT MOVIE CLASSICS","AMBIENT VIDEO"

REM Process each folder name to process
for %%A in (%Folders%) do (
  REM If the source folder doesn't exist (with month and year added) report as error
  if not exist "%BaseDir%\%%~A - %MM%-%YYYY%\" (
    echo *WARNING* Folder [%BaseDir%\%%~A - %MM%-%YYYY%] does not exist, skipped.
  ) else (
    REM If dest folder does not exist (with year added) create it
    if not exist "%DestDir%\%%~A\%%~A %YYYY%\" (
      md "%DestDir%\%%~A\%%~A %YYYY%\"
    )
  REM Move entire source folder to dest folder
  move "%BaseDir%\%%~A - %MM%-%YYYY%" "%DestDir%\%%~A\%%~A %YYYY%\" > NUL
  )
)

Open in new window

~bp
0
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39904332
Here's a powershell solution:
$inputPath = "W:"
$outputPath = "W:\Vid"

$month = "02"
$year = "2014"

$newPath = ""

gci $inputPath -Filter "*$month-$year" | %{

    #remove the 02-2014 part, with the space before
    $newPath = $_.BaseName.substring(0, $_.BaseName.length - 8)

    #if the path contained "-" before the date, remove it
    if ($newPath.Substring($newPath.Length - 1) -eq "-") {
        $newPath = $newPath.Substring(0, $newPath.Length -2)
    }

    #create the new path
    $newPath = "$outputPath\$newPath\$newPath $year"
    
    #copy the folder, contents included
    Copy-Item -Path $_.FullName -Destination $newPath -Recurse

    #check if the copy was succesfull. If yes, then delete the original folder
    if (Test-Path $newPath) {
        Remove-Item $_.FullName -Recurse -Force
    }
}

Open in new window

This will look for all folders that finish in "02-2014" (or however you change the variables to), then copy them according to the format in the output folder, test if the copy was done and then delete the original folders.

HTH,
Dan
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now