Discussion:
Move files based on date into new folder whilst keeping the struct
(too old to reply)
Dave Pearce
2009-12-17 13:09:01 UTC
Permalink
Hello wonder if you can help.

I have a folder with lot's of files written in it from 2005-present day.
What i need to script is move files from this location and sort them by years
whilst keeping the existing structure. I have looked at the syntax of xcopy
and robocopy but not sure whats the best way to move forward for exmaple

d:\docs\word\file1.doc (created in 2006) would move to d:\2006\word\file1.doc

d:\docs\excel\john\file2.xls (created in 2005) would move to
d:\2005\excel\john\file2.xls

And so on. I can make the script once i have an idea on the best way to take
it forward.

Many Thanks in advance.

Regards
Dave
--
ICT Development
Pegasus [MVP]
2009-12-17 17:37:29 UTC
Permalink
Post by Dave Pearce
Hello wonder if you can help.
I have a folder with lot's of files written in it from 2005-present day.
What i need to script is move files from this location and sort them by years
whilst keeping the existing structure. I have looked at the syntax of xcopy
and robocopy but not sure whats the best way to move forward for exmaple
d:\docs\word\file1.doc (created in 2006) would move to
d:\2006\word\file1.doc
d:\docs\excel\john\file2.xls (created in 2005) would move to
d:\2005\excel\john\file2.xls
And so on. I can make the script once i have an idea on the best way to take
it forward.
Many Thanks in advance.
Regards
Dave
--
ICT Development
Seeing that you mention robocopy and xcopy, you probably want a batch file
rather than a VB Script file. Here is one that will do the trick:
@echo off
set Source=d:\Docs
set Target=d:
set Year=2005
set /a NYear=%Year% + 1
set Switches= /s /mov /MinAge:%NYear%0101
robocopy "%Source%" "%Target%\%Year%" *.* %Switches%

Adjust the first three "set" commands to suit your environment. Note that
neither the Source nor the Target must have a trailing backslash. Run the
file for the oldest year first, then move up by one year at a time. I urge
you to do a trial run with a disposable source directory until you're
satisfied with the result.
Dave Pearce
2009-12-19 11:55:01 UTC
Permalink
This worked perfectly. Did the /COPY first to test.

Many Thanks for your help.

Kind Regards
Dave
--
ICT Development
Post by Pegasus [MVP]
Post by Dave Pearce
Hello wonder if you can help.
I have a folder with lot's of files written in it from 2005-present day.
What i need to script is move files from this location and sort them by years
whilst keeping the existing structure. I have looked at the syntax of xcopy
and robocopy but not sure whats the best way to move forward for exmaple
d:\docs\word\file1.doc (created in 2006) would move to
d:\2006\word\file1.doc
d:\docs\excel\john\file2.xls (created in 2005) would move to
d:\2005\excel\john\file2.xls
And so on. I can make the script once i have an idea on the best way to take
it forward.
Many Thanks in advance.
Regards
Dave
--
ICT Development
Seeing that you mention robocopy and xcopy, you probably want a batch file
@echo off
set Source=d:\Docs
set Year=2005
set /a NYear=%Year% + 1
set Switches= /s /mov /MinAge:%NYear%0101
robocopy "%Source%" "%Target%\%Year%" *.* %Switches%
Adjust the first three "set" commands to suit your environment. Note that
neither the Source nor the Target must have a trailing backslash. Run the
file for the oldest year first, then move up by one year at a time. I urge
you to do a trial run with a disposable source directory until you're
satisfied with the result.
.
Pegasus [MVP]
2009-12-19 14:04:33 UTC
Permalink
Post by Dave Pearce
This worked perfectly. Did the /COPY first to test.
Many Thanks for your help.
Kind Regards
Dave
--
ICT Development
Thanks for the feedback.

Loading...