Solved

Removing path and quotes in batch

Posted on 2014-03-22
3
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

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…
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 …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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