?
Solved

Batch Script

Posted on 2013-12-10
10
Medium Priority
?
336 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
Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

 
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 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

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

777 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