Move files and place a Windows link

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Move files and place a Windows link

#1 Post by darioit » 29 Dec 2015 02:22

Hello Everybody,
I find my old script to copy all particular extensione file from a disk to another disk replicating asis the same directory structure

Code: Select all

xcopy /yisd D:\*.7z Z:\D\%1
xcopy /yisd E:\*.7z Z:\E\%1


Now I like to improve this script deleting a file successfully copied and replace it with a Windows link that point to a new drive, how can I achieve this?

Thank you

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Move files and place a Windows link

#2 Post by aGerman » 29 Dec 2015 17:29

I fiddled with ROBOCOPY (which moves the files and outputs the the moved files) and MKLINK (which is able to create symbolic links).
Try that:

Code: Select all

@echo off &setlocal DisableDelayedExpansion
cd /d "%~dp0"
fsutil fsinfo drives|findstr /c:":\\">nul||(echo Run as Admin!&pause&exit /b)

set "src=D:"
set "dest=Z:\D"
set "ext=7z"

for /f %%i in ('cmd /von /u /c "echo(!src!"^|find /c /v ""') do  set /a "len=%%i-3"
for /f "tokens=*" %%i in (
  'robocopy "%src%" "%dest%" "*.%ext%" /mov /s /xj /xx /is /it /nc /ns /np /ndl /njh /njs /r:0 /w:0'
) do (
  set "f=%%i"
  setlocal EnableDelayedExpansion
  mklink "!f!" "!dest!!f:~%len%!"
  endlocal
)
pause

Make sure src and dest are absolute pathes without trailing backslashes. Since MKLINK requires elevated rights you have to run the batch file as admin.

Regards
aGerman

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: Move files and place a Windows link

#3 Post by darioit » 30 Dec 2015 03:31

This is not a script! This is a masterpiece !!!

It's works very well, thanks again!

Post Reply