UNC Paths Not Supported in called batch file

archivebatch-filecmdpushdunc

The purpose of the batch files is to loop through a directory, move all files with a modified date between x and y to a temp directory (located in an archive folder), create a .zip from temp directory, then finally delete the temp directory.

I am calling a batch from a batch. The initial batch uses pushd to retrieve the network path, but then when the next batch is called and the forfiles is used to move files into an archive, the UNC path error is thrown. "ERROR: UNC paths (\machine\share) are not supported."

The two .bat files are in the same directory in the shared network.

I have read the other answer for this similar issue, but none of the answers fix my problem.

First batch file:

@echo off
setlocal EnableExtensions
cls 
@pushd %~dp0

:firststep
........
code....
........
echo Calling...
CALL ArchiveTool.bat %MM% %yyyy% \\riskview\EBSArchive
echo Press any key to process next directory...
pause >nul

To here everything works properly.

Failing batch:

@echo off
setlocal EnableExtensions
.......
Code...
.......
md %3\Archive\%1-%2
forfiles /P %3 /D +%1/1/%2 /C "cmd /c if /I @FDATE LSS %mm%/1/%2 move @file                
%3\Archive\%1-%2 >NUL & echo|set /p=."

The directory is successfully created, but the forfiles fails.

Best Answer

UNC default paths are turned off by default as they used to crash older programs.[10]

The Dword registry value DisableUNCCheck at HKEY_CURRENT_USER\Software\Microsoft\Command Processor [10] allows the default directory to be UNC. CD command will refuse to change but placing a UNC path in Default Directory in a shortcut to Cmd or by using the Start command. start "" /d \127.0.0.1\C$ "cmd /k" (C$ share is for administrators).

From my entry at https://en.wikipedia.org/wiki/Batch_file#Setting_a_UNC_working_directory_from_a_shortcut