Solved

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

Posted on 2014-03-17
1
329 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

20 Experts available now in Live!

Get 1:1 Help Now