Solved

copying files from UNC in batch

Posted on 2014-03-10
1
412 Views
Last Modified: 2014-03-14
Hello,

  I am trying to copy files in UNC that are not drive mapped on the server. Apparently its not working for UNC, works file for full filenames.


My input file looks like:

"\\abc12244\myPDFS\firstfile.pdf","CompanyA.pdf","SubA","A"


My batch code to copy looks like:

set BaseDir=C:\Base
set AllDir=C:\All

 for /f "usebackq tokens=1-4 delims=," %%A in ("%ControlFile%") do (
  call :DoIt %%A %%B %%C %%D
 )


:DoIt

       if not exist "%BaseDir%\" mkdir "%BaseDir%"
        if not exist "%BaseDir%\%~4\" mkdir "%BaseDir%\%~4"
        if not exist "%BaseDir%\%~4\%~3\" mkdir "%BaseDir%\%~4\%~3"
        copy /Y "%1" "%BaseDir%\%~4\%~3\%~2"

       if not exist "%AllDir%\" mkdir "%AllDir%"
0
Comment
Question by:LuckyLucks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 39918757
"Copy" can definitely use UNC paths.
There's actually no need for the "DoIt" subroutine, it only makes things look more complicated. If you use it, you need to leave the script with a "goto :eof" before the :DoIt label; if you don't do this, you'll get errors, because the script will continue after it's done processing the input file, and then use the command line arguments (if any) in the DoIt loop.
Then there's no need to create the subfolders one after another. Last time that was required was in DOS, not in any NT based command shell.
So try this:
@echo off
setlocal
set ControlFile=C:\Temp\test.txt
set BaseDir=C:\Base
set AllDir=C:\All
for /f "usebackq tokens=1-4 delims=," %%A in ("%ControlFile%") do (
	if not exist "%BaseDir%\%%~D\%%~C" mkdir "%BaseDir%\%%~D\%%~C"
	copy /Y "%%~A" "%BaseDir%\%%~D\%%~C\%%~B"
)
if not exist "%AllDir%\" mkdir "%AllDir%"

Open in new window

0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question