Solved

Removing path and quotes in batch

Posted on 2014-03-22
3
299 Views
Last Modified: 2014-04-01
Hi

   I am looking to process a txt file that has the following format and get a new text file of the new format, also listed below. In essence, the batch would need to remove all drive and folders and unquote the first entry. Please help me with writing the batch code to do it.

Input file:
"Z:\B\1.pdf","newfile1.pdf",<mystring>,<mystring>

Would like:

1.pdf

Thanks
0
Comment
Question by:LuckyLucks
  • 2
3 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39948264
Don't know in batch, in PS you can do it like this:
$inputText = "`"Z:\B\1.pdf`",`"newfile1.pdf`",<mystring>,<mystring>"
$outputText = $inputText.Split("`"")[1] # get only the file name, with path
$outputText = $outputText.Split("\")[-1] # get only the file name
echo $outputText

Open in new window

HTH,
Dan
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 39948311
@echo off
(for /f "tokens=1 delims=," %%a in (oldfile.csv) do echo %%~nxa) >newfile.csv

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39948313
That means take the first part of the line upto the comma in file oldfile.csv and for each entry the ~ strips the quotes, and "nx" leaves the Name and eXtension of the filename only.  Whole lot redirected into one file, or you can do other processing in the loop rather than creating a new file.

Steve
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

816 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

12 Experts available now in Live!

Get 1:1 Help Now