subash
subash

Reputation: 4137

cmd does not support unc paths as current directories pushd

i was trying to copy a files modified today from one shared drive another shared drive. but when i execute the batch file, it displays the following error.

cmd does not support unc paths as current directories

the script is as below

@echo off


Set PhotosrcPath=\\hqcp-appsvr01\Files\ApplicationDocuments\AppDocs\49\PHOTO\
Set PhotodestPath=\\hqcp-appsvr02\Files\ApplicationDocuments\AppDocs\49\PHOTO\

::Copy photoFiles from server1 to server2 Made Or Modified Today


@echo off

set source=%d%%PhotosrcPath%
set dest=%d%%PhotodestPath%


pushd "%source%"
set t=%date:~4%
echo %t%
for /f %%a in ('dir /b /a-d /o-d') do call :PROCESS "%%a"
goto :eof
popd

:PROCESS
for /f %%j in ('echo %~t1') do set d=%%j
if "%d%"=="%t%" Xcopy /y %1 "%dest%"
goto :eof

Upvotes: 4

Views: 28081

Answers (2)

Bob
Bob

Reputation: 1055

net use X: \\hqcp-appsvr01\Files\ApplicationDocuments\AppDocs\49\PHOTO
net use Y: \\hqcp-appsvr02\Files\ApplicationDocuments\AppDocs\49\PHOTO

::Copy photoFiles from server1 to server2 Made Or Modified Today

@echo off

set source=X:\
set dest=Y:\

pushd "%source%"
set t=%date:~4%
echo %t%
for /f %%a in ('dir /b /a-d /o-d') do call :PROCESS "%%a"
popd
net use Y: /d /y
net use X: /d /y
goto :eof

:PROCESS
for /f %%j in ('echo %~t1') do set d=%%j
if "%d%"=="%t%" Xcopy /y %1 "%dest%"
goto :eof

Something like that might work. Look up NET USE for more information.

I'm curious why you aren't just using XCOPY - I would think that the /D command might do what you need. I would throw in a /M too.

xcopy \\hqcp-appsvr01\Files\ApplicationDocuments\AppDocs\49\PHOTO\*.* \\hqcp-appsvr02\Files\ApplicationDocuments\AppDocs\49\PHOTO\*.*  /y /d /m

Upvotes: 4

Benilda Key
Benilda Key

Reputation: 3092

There is no reason to use pushd. The following modification of the for loop may be enough.

for /f %%a in ('dir "%source%" /b /a-d /o-d') do call :PROCESS "%%a"

Upvotes: 1

Related Questions