Solved

Copy latest file that starts with "C36"

Posted on 2013-06-24
4
274 Views
Last Modified: 2013-07-18
Need a script that would copy the latest (modified date) file that starts with “c36”

FILE:  C36*.TXT (if duplicate exists, then copy only the lates file)
SOURCE = \\d9d75pardb01\Paragon Upload Files\Remittances\  
TARGET = \\ela-ps1\medicare remits$\Mcare 835 ERAs\

The folder will ocasionally have more than one file with same date, but different times:

FILE NAME, CREATE DATE
C2500013352A, 06/23/2013@1601
C360005edc1D, 06/24/2013@1055
C25000urf1055, 06/24/2013@1055
C36000qwe255, 06/24/2013@1315  <<<  i want to be able to copy only this file >>>>

REM - SETTING VARIABLES
setlocal enabledelayedexpansion
set Source=\\d9d75pardb01\Paragon

REM - SEARCH FOR EXISTING FILES
for /f "tokens=1 delims=[]" %%a in ('type "%~f0" ^| find /n "[BACKUPDATA]"') do set DataStart=%%a
set /a TypeCount = 0

REM - COPY 
for /f "tokens=1* skip=%DataStart% delims= " %%a in ('type "%~f0"') do (
	set /a TypeCount += 1
	set SourceType[!TypeCount!]=%%a
	set Target[!TypeCount!]=%%b
)
for /l %%i in (1, 1, %TypeCount%) do (
	robocopy.exe "%Source%" "!Target[%%i]!" !SourceType[%%i]! /MIR /r:2 /w:1
)
goto :eof
[BACKUPDATA]
C36*.* \\ela-ps1\medicare remits$\Mcare 835 ERAs\

Open in new window

0
Comment
Question by:epicazo
4 Comments
 
LVL 3

Accepted Solution

by:
telczj9 earned 500 total points
ID: 39272415
the code below will copy newest file matching the C36*.TXT creteria:

@echo off
REM -- FILE:  C36*.TXT (if duplicate exists, then copy only the lates file)
SOURCE = \\d9d75pardb01\Paragon Upload Files\Remittances\  
TARGET = \\ela-ps1\medicare remits$\Mcare 835 ERAs\


for /f "tokens=*" %%i in ('dir /od /b %SOURCE%\C36*.TXT') do (
 set freshesh_c36_file=%%i
) 

copy %SOURCE%\%freshesh_c36_file% %TARGET%

Open in new window

0
 
LVL 59

Expert Comment

by:LeeTutor
ID: 39336864
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
 

Author Closing Comment

by:epicazo
ID: 39336865
sorry for the delay.  thank you so much
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

First some basics on Windows 7 Backup.  It has 2 components one is a file based backup which is stored in .zip files each zip is split at around 200 Megabytes and there is the Image Backup which is as the name implies a total image of the partition …
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now