Solved

Batch Script

Posted on 2013-12-10
10
321 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 250 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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 70

Accepted Solution

by:
Qlemo earned 250 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

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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