Solved

Changing the path of a column in a text file using batch

Posted on 2014-03-17
1
336 Views
Last Modified: 2014-03-17
Hi,


I want to replace the first column of the text file with another drive location and strip all the subfolders in between. How can I accomplish this in batch?

"\\myserver\sub1\sub2\abc1.pdf","ABC_018-2002-A_0_20011231_20020215__1.pdf","ABCInc","A"


becomes:

"Z:\process\abc1.pdf","ABC_018-2002-A_0_20011231_20020215__1.pdf","ABCInc","A"
0
Comment
Question by:LuckyLucks
1 Comment
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 39934899
Try this:
@echo off
setlocal
set SourceFile=D:\Temp\test.txt
set TargetFile=D:\Temp\test-new.txt
set NewFolder=Z:\process
if exist "%TargetFile%" del "%TargetFile%"
echo Processing '%SourceFile%' ...
for /f "tokens=1* delims=," %%a in ('type "%SourceFile%"') do (
	>>"%TargetFile%" echo "%NewFolder%\%%~nxa",%%b
)
echo ... done.

Open in new window

Input and output file location can be passed using the command line or queried for if you prefer that.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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 …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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…

806 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