Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Batch Script

Posted on 2013-12-10
10
Medium Priority
?
344 Views
Last Modified: 2014-10-27
1) The first script should copy data from \\sportographystorage\sportography\SPEEDJOBS\XXXXXX\SCANS\ORDERS2 to E:\Sportography\archive which is older than 6 months. While copying we need to make sure directory structure post job number(XXXXX) should remain same.

2) The second script should scan E:\Sportography\archive and delete files which are older than 18 months.



Note:-- SCANS\ORDERS2 subfolders are not present in each and every XXXXXXXX, so we need to first check if these exists or not. If they are there then we need to copy the files.
0
Comment
Question by:CHAUDHARYAKSHAY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Author Comment

by:CHAUDHARYAKSHAY
ID: 39718956
@ECHO OFF


REM Set locations

SETLOCAL



set "location=\\sportographystorage\sportography\SPEEDJOBS\"
for /r "%location%" /d %%d in (*) do (
  xcopy "%%d\SCANS\ORDERS2" "C:\Users\achau\Desktop\Transfer\%%d\SCANS\ORDERS2\" /s /c /d /e /h /i /r /y /d:06-01-2013
)
0
 

Author Comment

by:CHAUDHARYAKSHAY
ID: 39718958
So far I am able to make this script but how to use date in xcopy to copy the files which are 6 months old
0
 
LVL 28

Assisted Solution

by:Bill Bach
Bill Bach earned 1000 total points
ID: 39722594
I would recommend using ROBOCOPY for this, as it has options for handling files older than a specific date, and XCOPY does not.  RoboCopy is built into the newer operating systems, and is downloadable from Microsoft for older OS releases.

Using a /MINAGE:180 should copy files that are approximately older than 6 months.  If you need to be more accurate, then you may have to calculate the MINAGE value based on the number of days in each of the last 6 months.  However, this likely has little additional value, and 180 should be OK.

If you use the /MOV option, then you can do both steps (copy and delete) in one fell swoop.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 43

Expert Comment

by:Rob
ID: 39722625
+1 BillBach.  I just don't use (x)copy any more.  Robocopy is far more superior and reliable.
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 39722660
Thanks, tagit.  I actually use a shareware utility called Beyond Compare (www.beyondcompare.com).  It's freaky fast, and it supports both scripts from a command line (for automated backup use) AND GUI operation (for manual updates or resolving conflicts) equally well.
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 1000 total points
ID: 39739113
Note that
for /r "%location%" /d %%d in (*) do (

Open in new window

is an undocumented combination of switches. You should be able to use either /R or /D, but not both. But it works. Anyway, it is not what you want. You just want to parse a single level of folders, which is /D, while /R is recursive (going thru all level of subfolders).

I agree to use RoboCopy, if you want to stick with what is available with your OS. We can perform both tasks with RoboCopy:
@echo off
setlocal
set dest=E:\Sportography\archive

REM Task 1: Copy files older than 180 days:
pushd \\sportographystorage\sportography\SPEEDJOBS\
for /d %%D in (*) do if exist "%%~D\SCANS\ORDERS2\" ^
robocopy "%%~D\SCANS\ORDERS2" "%dest%\SCANS\ORDERS2\" /NJH /NJS /S /NDL /MinAge:180
popd

REM Task 2: Delete archive files older than 18 months:
for /F "tokens=*" %%F in ('robocopy %dest% %dest% /IS /s /minage:180 /NDL /NP /L /NS /NC /NJH /NJS') do @echo del "%%F"

Open in new window

The second part doesn't actually delete the files, it only shows a "what-if". Remove the "echo" do let it do its evil work.

However, it doesn't make much sense without further actions. After deleting the files older than 18 months, the next copy will reintroduce that files, unless they are removed from the original folder. Or the first RoboCopy gets an additional switch for ignoring files older than 18 months: /maxage:540.
On the other hand, it seems to be more appropriate to move the files to the archive folder instead of copying.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses

610 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