Solved

Removing path and quotes in batch

Posted on 2014-03-22
3
296 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

19 Experts available now in Live!

Get 1:1 Help Now