Solved

Copying files from a server and text processing

Posted on 2014-04-16
3
181 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 53

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 53

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: 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…
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 …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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