Solved

Copy latest file that starts with "C36"

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
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…
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…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
Suggested Courses

628 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