Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-03-17
1
Medium Priority
?
350 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 85

Accepted Solution

by:
oBdA earned 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

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 …
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

926 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