Hi,

I have a file test.txt, this file has many pathnames such as,

C:\xx\yy\zzz\bd\hello
C:\xx\yy\zzz\bd\bye
C:\xx\yy\zzz\bd\cd\de\name
C:\xx\yy\zzz\bug
C:\xx\yy\zzz\dfdfd\gt

I want to use basename or any other method to get the the last filename. At the moment in my batch script im unable to loop through the file and use basename on each path. Any other way of solving the problem can also be tried.

Thanks,
Rahul

Recommended Answers

All 2 Replies

Ok I got it working, i am able to get the last file name using this code,

@echo off

rem get files into  text file

set PWD=%CD%
set WWW=%1
set WKD=%WWW%

CD %WKD%

FOR /F "tokens=*" %%a in (testing2.txt) do (

basename %%a 
)

Is it possible to send all the data to a txt now? If I try sending the stuff to the txt file at the end I just get the last pathname as each time the loop runs it erases the contents of the previous file and puts the new content. This is what im using

@echo off

rem get files into  text file

set PWD=%CD%
set WWW=%1
set WKD=%WWW%

CD %WKD%

FOR /F "tokens=*" %%a in (testing2.txt) do (

basename %%a > test.txt %%a
)
awk -F '\' '{ printf "%s\n", $NF }' "$file"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.