[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

copying files from UNC in batch

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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

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…
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 …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

649 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