cmd bat文件,允许访问网络共享

时间:2014-02-14 11:55:37

标签: batch-file cmd file-permissions

我有以下代码可以很好地比较2个最新文件并将差异输出到一个单独的文件夹但是在:getLatestFileInFolder我需要它来访问SAN网络位置。目前它只能访问本地。请允许有人为我调整此代码。我需要访问的位置是san“\ 3663vfas01 \ Biztalk $ \ Live”

@echo off
cd /d C:\Users\test\Important Structure\Development\AX copy
for /f %%a in ('dir /b /od /a-d /tw') do (set latest=%%a)   

setlocal enableextensions disabledelayedexpansion

call :getLatestFileInFolder "C:\Users\test\Important Structure\Development\AX copy" latestC
call :getLatestFileInFolder "C:\Users\test\Important Structure\Development\Reflex copy" latestD


if not defined latestC ( echo NO File in C & exit /b )
if not defined latestD ( echo NO File in D & exit /b )

for /f "tokens=1,*" %%a in (
    'diff "%latestC%" "%latestD%" ^| findstr /r /c:"^<" /c:"^>"'
) do (
    >> "C:\Users\test\Important Structure\Development\Error\%latest%" echo(%%b
)

endlocal
exit /b

:getLatestFileInFolder folderToSearch variableToReturn
setlocal
set "folder=%~1" & if not defined folder set "folder=%cd%"
set "latest="
pushd "%folder%"
for /f "tokens=*" %%a in ('dir /b /o-d /a-d /tw 2^>nul') do (set "latest=%%~fa" & goto :latestFileFound)
:latestFileFound
popd
endlocal & set "%~2=%latest%" & goto :eof

2 个答案:

答案 0 :(得分:0)

如果您的意思是需要对网络路径执行等效的cd命令,那么您可以使用pushd来暂时分配映射驱动器,例如

pushd "\\3663vfas01\Biztalk$\Live"

答案 1 :(得分:0)

EDITED

更改此行:

set "fC=C:\Users\test\Important Structure\Development\AX copy"

到此:

set "fC=\\3663vfas01\Biztalk$\Live"

在这段代码中,它应该像你的一样运作:

@echo off

set "fC=C:\Users\test\Important Structure\Development\AX copy"
set "latestC="
for /f "delims=" %%a in ('dir "%fC%" /b /od /a-d /tw 2^>nul') do set "latest=%%a" & set "latestC=%fC%\%%a"

set "fD=C:\Users\test\Important Structure\Development\Reflex copy"
set "latestD="
for /f "delims=" %%a in ('dir "%fD%" /b /od /a-d /tw 2^>nul') do set "latestD=%fD%\%%a"

if not defined latestC ( echo NO File in C & exit /b )
if not defined latestD ( echo NO File in D & exit /b )

for /f "tokens=1,*" %%a in (
    'diff "%latestC%" "%latestD%" ^| findstr /r /c:"^<" /c:"^>"'
) do (
    >> "C:\Users\test\Important Structure\Development\Error\%latest%" echo(%%b
)