Solved Copy file:If empty or not exists - NOTIFY- if exists - COPY

June 19, 2012 at 12:29:41
Specs: Windows 7
Hi

I am having source and destination folder locations...I have to check if the file in source is empty or not exists then notify(for which I have the code). What I have to do is delete the file in destination location if any exists and copy form source to destination by renaming the file. I am having multiple files in the source and have to do same for all the files.

Files in source are like:
File(1).DAT
File(2).DAT
File(3).DAT.......

and in destination, it should be copied as:

Rev(1).DAT
Rev(2).DAT
Rev(3).DAT......

Please help me, Thank you !!


See More: Copy file:If empty or not exists - NOTIFY- if exists - COPY

Report •


#1
June 19, 2012 at 18:01:41
✔ Best Answer
I'm kind-of confused, but I'll make a stab at it...

@echo off & setlocal enabledelayedexpansion
set srcpath=c:\source
set destpath=d:\dest
for /f "tokens=1* delims=(" %%a in ('dir /b %destpath%\rev*.dat') do (
set sfile=%srcpath%\file(%%b
if not exist !sfile! (
>> logfile echo source !sfile! not there
) else (
copy /y %srcpath%\!sfile! %destpath%\%%a(%%b
)
)
:end

NOT tested!


Report •
Related Solutions


Ask Question