Solved Copy Files by Renaming after Checking if it Exists and.....

June 21, 2012 at 12:30:15
Specs: Windows 7
I have few files in source location to be copied to destination location by renaming them. But before that I have to check if the file exists or is empty(no data in file) in the source location. If it does not exist or is empty in the source then do nothing.
Else copy from source to the destination by renaming it.
Example would be like
Source has files:
File(1).dat
File(2).dat
File(3).dat
Destination should have:
Rev(1).dat
Rev(2).dat
Rev(3).dat
assuming all files are non-empty. Thank you!!

See More: Copy Files by Renaming after Checking if it Exists and.....

Report •

#1
June 22, 2012 at 09:55:10
✔ Best Answer
Relies on forfiles to check the filesize so this will only work on Vista+ OS's.

@echo off & setlocal enabledelayedexpansion
if exist $$$ del $$$
set src=c:\source
set dest=c:\destination
pushd !scr!
forfiles /m *.dat /c "cmd /c if @fsize neq 0 >>$$$ echo @file"
for /f "tokens=*" %%f in (
'type $$$'
) do (
set $=%%f
for /f "tokens=*" %%i in (
!$!
) do (
copy "!$!" "!dest!\Rev!$:~-7!
))
popd
goto :eof

Tony


Report •
Related Solutions


Ask Question