Rename Files using wildcard paths
<p>Recently I started working and my first task is to write a batch file that automatically changes filenames to filename_date with the original file-ending.
For that you should be able to write paths into a textfile (e.g. paths.txt) and when you start the program, it should take any line (=path->file) from there and rename it.
I got it to work on my PC quiet well but as I gave it to testing they asked to make the use of wildcards <code>Z:\Path\*.*</code> possible.
My current code looks as follows:</p>

<pre><code>@echo off
setlocal EnableDelayedExpansion
cd %~dp0    

For /F "tokens=*" %%m in (paths.txt) do (

set path=%%~dpm
set name=%%~nxm

pushd "!path!"
dir

For /r !path! %%f in (!name!) do (

set path=%%~dpf
set name=%%~nf
set ending=%%~xf
set datsave=%%~nxf

set "name=!name!_"
set "name=!name!!date:~6,4!"
set "name=!name!!date:~3,2!"
set "name=!name!!date:~0,2!"

set "name=!name!!ending!"

copy "!datsave!" "!name!"

del "!datsave!"
cls
popd
)

)
</code></pre>

<p>I know that a lot of it is probably easier and more efficient to do, but this is my first batch project and I am quiet happy except for the wildcard problem. 
So an example would be:
<code>C:\Some\Path\*.*</code></p>

<p>This line would be in paths.txt.
With the splitting </p>

<pre><code>set path=%%~dpf
set name=%%~nf
set ending=%%~xf
set datsave=%%~nxf
</code></pre>

<p>I get the following:</p>

<pre><code>path: C:\Some\Path
name: C:\Some\Path
ending: -empty-
datsave: C:\Some\Path
</code></pre>

<p>because name is set to the Path at the start of the first FOR-Loop. But that seems to be working if I do not use wildcards.</p>

<p>Now the question: Why does this happen and how do I get rid of it? Or do I just use the wrong type of wildcards?</p>

<p>Again: This is my first time I work with batch, so it might be something simple ;)</p>