Deb
Deb

Reputation: 5649

How to Extract the file name from a full path in bat?

A variable %result% contains the path "D:\My Folder1\My Folder 2\My Folder 3\The Important File.txt" . I want to store The Important File in some another variable. That is, I want to extract the file name (Without extention) from a full path.

Upvotes: 2

Views: 2756

Answers (2)

foxidrive
foxidrive

Reputation: 41224

This should give you what you need.

@echo off
for %%a in ("%result%") do set "newvariable=%%~na"

Upvotes: 3

Related Questions