John Smith
John Smith

Reputation: 363

Batch: Script already gets names of folders and subfolders - how do I get filenames without extension?

This script gets the folder-names and its sub-folder-names and sve them into a HTML-file. I also need the filenames of all files which are in the subfolders (without the extension). I pimped the script with some HTML.

list.cmd

@echo off
chcp 1252
del D:\list.html
for /f "tokens=*" %%G in ('dir /ad /b D:\packing') do (
echo ^<center^>^<b^>^<font size="4" color="#ffffff" face="Lucida Sans Unicode, Lucida Grande" style="background-color:#4682b4;"^>^&nbsp; >> D:\list.html
echo %%G ^&nbsp; >> D:\list.html
echo ^</b^>^<a href="#" style="color:#4682b4; text-decoration:none;"^> >> D:\list.html
echo ^</a^>^</font^>^<br^>^</center^> >> D:\list.html
echo ^<center^>^<font size="2" color="#000000" face="Verdana"^> >> D:\list.html
call D:\packing\list2.cmd "%%G"
echo ^</font^>^</center^>^<br^>^<br^> >> D:\list.html
)

list2.cmd

for /f "tokens=*" %%H in ('dir /ad /b D:\packing\%1') do echo %%H ^<br^> >> D:\list.html
echo. >> D:\list.html

Upvotes: 1

Views: 1346

Answers (1)

Bali C
Bali C

Reputation: 31221

You can get the file name without the extension for every file in all subfolders using

for /r C:\dirname %%a in (*) do echo %%~na

That will echo them all. Just modify and use it in your script where you need it.

Upvotes: 2

Related Questions