Solved

Removing path and quotes in batch

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Batch File to find and replace a string 15 117
Installing Git and chefdk via bat script 8 113
Convert .csv to tab delimited text 11 50
Remote start and stop of service 3 47
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
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 …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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