copy and kill file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sal21
Posts: 22
Joined: 12 Jul 2016 12:58
Location: Italy

copy and kill file

#1 Post by sal21 » 02 Aug 2018 03:40

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

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: copy and kill file

#2 Post by SIMMS7400 » 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
	

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: copy and kill file

#3 Post by Squashman » 02 Aug 2018 08:51

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.

Post Reply