Solved

Copying files from a server and text processing

Posted on 2014-04-16
3
174 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
  • 2
3 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
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 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now