Code: Select all
Set FileDate=%date:/=%
for %%i in (*.txt) do ren %%i %%i_%FileDate%.txt
I'm obviously getting an additional dot and file extension. What is the reason?
thanks,
Mark
Moderator: DosItHelp
Code: Select all
Set FileDate=%date:/=%
for %%i in (*.txt) do ren %%i %%i_%FileDate%.txt
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$date=!date:/=!"
for %%? in (
"*.txt"
) do echo.ren "%%~?" "%%~n?_!$date!%%~x?"
pause
exit
Code: Select all
ren "Nieuw - Tekstdocument.txt" "Nieuw - Tekstdocument_vr 16032012.txt"
Druk op een toets om door te gaan. . .
Code: Select all
@echo off
for /?
pause
Ed Dyreen wrote:'Code: Select all
for %%? in (
*.txt
) do echo.ren "%%~?" "%%~n?_!$date!%%~x?"
'foxidrive wrote:Why not use %%a or %%A where there is a logical connection to %%b and %%c etc?
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$=will it work ?"
for %%! in ( "$" ) do for %%a in ( "$" ) do echo. "!%%~a!"
for %%! in ( "$" ) do for %%? in ( "$" ) do echo. "!%%~?!"
pause
exit
Code: Select all
""
"will it work ?"
Druk op een toets om door te gaan. . .
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$=will it work ?"
for %%a in ( "$" ) do for %%b in ( "$" ) do echo. "!%%~b!"
for %%! in ( "$" ) do for %%? in ( "$" ) do echo. "!%%~?!"
pause
exit
Code: Select all
FOR /F %%$ in ("hello") do (
echo %%$ works
echo %%~$ fails, but why?
)
jeb wrote:I agreee with foxidrive and Dave, I would avoid also non-alpha-numericals as FOR-variables, as it's too easy to create none obvious problems.
Like this one (reading last week)Code: Select all
FOR /F %%$ in ("hello") do (
echo %%$ works
echo %%~$ fails, but why?
)
Code: Select all
%~$PATH:I
I didn't encounter any none obvious problems in my 11.000 lines batch file.jeb wrote:it's too easy to create none obvious problems.
Code: Select all
@echo off &setlocal
del "dummy.txt" 2>nul
for %%a in ("dummy.txt") do echo %%~aa
for %%A in ("dummy.txt") do echo %%~Aa
for %%A in ("dummy.txt") do echo %%~AA
>>"dummy.txt" type nul
for %%a in ("dummy.txt") do echo %%~aa
for %%A in ("dummy.txt") do echo %%~Aa
for %%A in ("dummy.txt") do echo %%~AA
pause
Code: Select all
ECHO ist ausgeschaltet (OFF).
dummy.txta
ECHO ist ausgeschaltet (OFF).
--a------
dummy.txta
--a------
Drücken Sie eine beliebige Taste . . .
Code: Select all
@echo off &setlocal
del "dummy.txt" 2>nul
echo.test0
for %%a in ("dummy.txt") do echo %%~aa
echo.test1
for %%A in ("dummy.txt") do echo %%~Aa
>>"dummy.txt" type nul
echo.test2
for %%a in ("dummy.txt") do echo %%~aa
echo.test3
for %%A in ("dummy.txt") do echo %%~Aa
pause
Code: Select all
test0
ECHO is off (uit).
test1
dummy.txta
test2
--a--c---
test3
dummy.txta
Druk op een toets om door te gaan. . .
Ed Dyreen wrote:That's weird, I couldn't explain it![]()
Code: Select all
%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string