Solved

Copy latest file that starts with "C36"

Posted on 2013-06-24
4
286 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
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…

761 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