Page 1 of 1

copy and kill file

Posted: 02 Aug 2018 03:40
by sal21
batch, please.. tkx.
have two lan dir:

source dir:
\\mylnadir1\dir1\
destination dir:
\\mylnadir2\dir2\

from source dir i need to loop all .txt files (only this type with .txt), check if in destionation dir are present if not copy, from source and paste in destination, naturally kill file from source...

tath is all.
tkx

Re: copy and kill file

Posted: 02 Aug 2018 05:51
by SIMMS7400
Untested:

Code: Select all

SET "SOURCE_DIR=\\mylnadir1\dir1"
SET "DEST_DIR=\\mylnadir2\dir2"

PUSHD "%SOURCE_DIR%"
	FOR /F %%A IN ("*.txt") DO (
		IF NOT EXIST "%DEST_DIR%\%%~A" (
			COPY /Y "%%~A" "%DEST_DIR%"
			DEL /F /Q "%%~A"
		)
	)
POPD
	

Re: copy and kill file

Posted: 02 Aug 2018 08:51
by Squashman
SIMMS7400 wrote:
02 Aug 2018 05:51
Untested:

Code: Select all

SET "SOURCE_DIR=\\mylnadir1\dir1"
SET "DEST_DIR=\\mylnadir2\dir2"

PUSHD "%SOURCE_DIR%"
	FOR /F %%A IN ("*.txt") DO (
		IF NOT EXIST "%DEST_DIR%\%%~A" (
			COPY /Y "%%~A" "%DEST_DIR%"
			DEL /F /Q "%%~A"
		)
	)
POPD
	
Remove the /F.