Solved

copying files from UNC in batch

Posted on 2014-03-10
1
407 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
1 Comment
 
LVL 84

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

790 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