?
Solved

copying files from UNC in batch

Posted on 2014-03-10
1
Medium Priority
?
416 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

770 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