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

Posted on 2014-03-17
Medium Priority
Last Modified: 2014-03-17

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?



Question by:LuckyLucks
1 Comment
LVL 86

Accepted Solution

oBdA earned 2000 total points
ID: 39934899
Try this:
@echo off
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.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…

624 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