Script for Automatically moving files older than 'X' days

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
marianandan
Posts: 2
Joined: 22 Aug 2014 14:20

Script for Automatically moving files older than 'X' days

#1 Post by marianandan » 22 Aug 2014 14:25

Hello,

I am looking for a DOS script for automatically moving files which are older than 'X' number of days. My platform is Windows 7.

Thanks in advance.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Script for Automatically moving files older than 'X' day

#2 Post by foxidrive » 23 Aug 2014 00:53

forfiles.exe can help you there.

Ask specific questions if you have trouble with it.

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

Re: Script for Automatically moving files older than 'X' day

#3 Post by Yury » 23 Aug 2014 21:29

Code: Select all

@echo off

set X=30
set "source=C:\Work"
set "destination=D:\Archive"

robocopy "%source%" "%destination%" /mov /minage:%X%

exit /b

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Script for Automatically moving files older than 'X' day

#4 Post by foxidrive » 23 Aug 2014 22:10

That's a good solution Yury.

bars143
Posts: 87
Joined: 01 Sep 2013 20:47

Re: Script for Automatically moving files older than 'X' day

#5 Post by bars143 » 23 Aug 2014 23:52

Yury wrote:

Code: Select all

@echo off

set X=30
set "source=C:\Work"
set "destination=D:\Archive"

robocopy "%source%" "%destination%" /mov /minage:%X%

exit /b



hi Yuri,

my netbook has changed from window 7 to XP
what is equivalent of ROBOCOPY in window xp sp3 ?
or can you give me scripts like above for use in window xp sp3 ?
thanks.

Bars

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: Script for Automatically moving files older than 'X' day

#6 Post by Squashman » 24 Aug 2014 14:41

Use robocopy from the Windows 2003 resource kit

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Script for Automatically moving files older than 'X' day

#7 Post by ShadowThief » 24 Aug 2014 15:02

Squashman wrote:Use robocopy from the Windows 2003 resource kit

Maybe he's working for a company whose User Access Policy doesn't allow him to install programs. Maybe he needs the program to work on multiple Windows XP computers with unknown configurations. Pure batch > using other programs.

pieh-ejdsch
Posts: 239
Joined: 04 Mar 2014 11:14
Location: germany

Re: Script for Automatically moving files older than 'X' day

#8 Post by pieh-ejdsch » 24 Aug 2014 15:26

For use the robocopy.exe it does not requirement to install on System.
Into variable PATH add the path from downloaded robocopy.exe.

Phil

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Script for Automatically moving files older than 'X' day

#9 Post by ShadowThief » 24 Aug 2014 15:43

pieh-ejdsch wrote:For use the robocopy.exe it does not requirement to install on System.
Into variable PATH add the path from downloaded robocopy.exe.

Phil

It still doesn't come with the system normally and has to be downloaded. Some places have a policy against that as well.

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Script for Automatically moving files older than 'X' day

#10 Post by einstein1969 » 24 Aug 2014 23:45

It's possible use xcopy + move?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Script for Automatically moving files older than 'X' day

#11 Post by foxidrive » 25 Aug 2014 03:40

ShadowThief wrote:Some places have a policy against that as well.


That's true ShadowThief, though they need to state that limitation when asking for help, as they are already aware of it.

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Script for Automatically moving files older than 'X' day

#12 Post by ShadowThief » 25 Aug 2014 03:45

foxidrive wrote:
ShadowThief wrote:Some places have a policy against that as well.


That's true ShadowThief, though they need to state that limitation when asking for help, as they are already aware of it.

I totally agree, but people have a tendency to skip over vital information in their first post, especially if they're new to forums. Also, I'm also thinking of the people months from now who find this thread in a Google search and need a pure batch response.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Script for Automatically moving files older than 'X' day

#13 Post by foxidrive » 25 Aug 2014 04:22

ShadowThief wrote: find this thread in a Google search and need a pure batch response.


Purely in the spirit of discussion, I think fewer people will use XP as the time passes and every machine will have robocopy installed by virtue of it being a default tool in Vista and later.

It is possible that a pure batch solution for this task will be difficult to do in a robust way, that is not tied to language and regional settings.
Forfiles.exe is another tool that can be used - it also needs to be downloaded for XP.

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Script for Automatically moving files older than 'X' day

#14 Post by ShadowThief » 25 Aug 2014 04:49

foxidrive wrote:
ShadowThief wrote: find this thread in a Google search and need a pure batch response.


Purely in the spirit of discussion, I think fewer people will use XP as the time passes and every machine will have robocopy installed by virtue of it being a default tool in Vista and later.

It is possible that a pure batch solution for this task will be difficult to do in a robust way, that is not tied to language and regional settings.
Forfiles.exe is another tool that can be used - it also needs to be downloaded for XP.

Very true. After a little investigation, it would appear that my concerns were unfounded, as Googling a way to move files older than X days via xcopy will show this stackoverflow answer by dbenham: http://stackoverflow.com/a/8905993

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Script for Automatically moving files older than 'X' day

#15 Post by foxidrive » 25 Aug 2014 05:09

Bewdy.

I think the OP has disappeared...

Post Reply