File name manipultation question

March 19, 2009 at 14:04:11
Specs: Windows Vista

I'm trying to recurse through a directory tree, and when I find a certain file I want to rename it to "name of directory"+".nfo"

So...let's say I find tvshow.nfo like this:
Y:\Video\Misc Series\The Simpsons\tvshow.nfo
(I don't know how deep the tree might be, so it may be fewer or more subdirectories)
What I want to do is to rename "tvshow.nfo" -> "The Simpsons.nfo".

Anyone know how to extract only the last part of the directory? My though is something along the lines of %~pI and then split by "/" or "\", and then only using the last one...?...

Any help would be greatly appreciated!

Cheers :D

See More: File name manipultation question

Report •

March 19, 2009 at 15:52:32
:: get last token of a path

@echo off & setLocal EnableDelayedExpansion

if %1'==' echo what path? && goto :eof
set str=%1

for /f "tokens=1* delims=\" %%a in ("!str!") do (
set tok=%%a
if not "%%b"=="" (
set str=%%b
goto :main
echo folder is !tok!

If at first you don't succeed, you're about average.


Report •

March 19, 2009 at 19:02:32
That was quick! Thanks :D

Report •

Related Solutions

Ask Question