Solved

Copying files from a server and text processing

Posted on 2014-04-16
3
182 Views
Last Modified: 2014-04-18
Hi EEE,


I have a txt file like below. I need to fetch the first value inside [ ]
(only the file name so example0eef817e-fdde-471a-b5d1-1bc627213d51.pdf)  and put them into a text file, file_leftover. Then I need to iterate thru these and copy from the server. It could occur in two paths on the server:

\\123456-PROD\AttachedDocuments\
\\123456-PROD\AttachedDocuments\Set


 How can I do this?

File:

*WARNING* Data file ["F:\Data_Pull_Feb42014\0eef817e-fdde-471a-b5d1-1bc627213d51.pdf"] was not found or subfolder ["DailyVitamin"] not created.
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
  • 2
3 Comments
 
LVL 54

Expert Comment

by:Bill Prew
ID: 40005655
Will there be more than one file name in [] in the text file, and you need to extract them all?

Can you give a more comprehensive example of the text file, showing why you said "I need to fetch the first value". Can there be multiple paths inside the same []?  If so what does that look like?

~bp
0
 

Author Comment

by:LuckyLucks
ID: 40005660
No only one filename ever. So always one full path.

The first value I say because in the line there is a second [] that contains something else and I don't need anything from the second [ ].
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 40005702
Okay, hopefully I understood what you needed, this seemed to do what you described when I tested it here, give it a try.

@echo off
setlocal EnableDelayedExpansion

set InFile=textfile.txt
set OutFile=file_leftover.txt
set SearchFolders="\\123456-PROD\AttachedDocuments\","\\123456-PROD\AttachedDocuments\Set"
set DestDir=c:\

if exist "%OutFile%" del "%OutFile%"

for /f "tokens=2 delims=[]" %%A in ('findstr /r /c:"[.*]" "%InFile%"') do (
  for %%B in (%SearchFolders%) do (
    if exist "%%~B\%%~nxA" (
      echo %%~B\%%~nxA>>"%OutFile%"
      copy "%%~B\%%~nxA" "%DestDir%"
    )
  )
)

Open in new window

~bp
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…

730 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