If %%c is temp.bak how do i remove the .bak

August 25, 2011 at 06:54:34
Specs: Windows XP
If %%c is Temp.bak and I want to add a date/timestamp before the .bak how do I do that?

See More: If %%c is temp.bak how do i remove the .bak

Report •


#1
August 26, 2011 at 19:57:55
        set input=%%c

        for /f "tokens=1-2 delims=." %%1 in ("!input!") do (
            set filename=%%1 %date% %time%.%%2
  
)



Please come back & tell us if your problem is resolved.


Report •

#2
August 27, 2011 at 01:43:21
Assuming that "%%c" is already a for variable, why not use the modifiers:

rem assumes "/:" as date/time seperators
echo "%%~nc-%date:/=.%-%time::=.%.%%~xc"


Report •

#3
August 27, 2011 at 19:18:06
neat trick...

I see that you can modify a var by adding the : and an expression. As in
echo %date:/=.%

this technique of using the : and the expression is that called something that I can go read about? what's the : actually do here and it the stuff on the right of the colon just a regex like I would use in grep?


Report •

Related Solutions

#4
August 27, 2011 at 23:26:31
this technique of using the : and the expression is that called something that I can go read about?

You can find more info by going to the command line and typing in "set /?". There is also quite a lot of other info included.

what's the : actually do here and it the stuff on the right of the colon just a regex like I would use in grep?


The ":" is presumably just a marker to tell cmd that extended variable expansion is being used. It is also used for substrings in combination with "~".

Not really regex, it's just a very simple string replace function, it doesn't do any real regex.

%var:string=replacement%

The replacement can be blank to delete the string.

It does have one little extra trick though:

%var:*string=replacement%

This will remove all characters from the start of the variable up to and including "string", but will not replace occurrences of "string" thereafter. It would seem logical that the use of the wild card would work in additional ways, but it doesn't.

There are also a couple of bugs.

"string" cannot contain the character "=", although "replacement" can. This is because the first "=" is used to delimit "string" and "replacement".

Due to the use of the asterisk as a wild card and a tilde to denote substrings, "string" cannot be a literal string that starts with either "*" or "~".

Although cmd has an escape character("^"), it doesn't fix these problems.


Report •

#5
August 29, 2011 at 07:56:37
Here is what I am trying to do;

:continue1
del /f /q C:\James\data\%JOB%\temp*.tmp

@echo off
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set TODAY=%year%%month%%day%
echo %TODAY%

for /f "tokens=1 delims=: " %%h in ('time /T') do set hour=%%h
for /f "tokens=2 delims=: " %%m in ('time /T') do set minutes=%%m
for /f "tokens=3 delims=: " %%a in ('time /T') do set ampm=%%a
set NOW=%hour%-%minutes%-%ampm%
echo %NOW%

pause

mkdir C:\James\data\%JOB%\backups\%TODAY%

dir /b C:\James\data\%JOB%\*.bak > C:\James\data\%JOB%\temp_%JOB%-%TYPE%-%ENV%-%FRQ%_dirlist.tmp

for /f %%c in (C:\James\data\%JOB%\temp_%JOB%-%TYPE%-%ENV%-%FRQ%_dirlist.tmp) do (

if NOT EXIST C:\James\data\%JOB%\backups\%TODAY%\temp*.bak (
copy C:\James\data\%JOB%\%%c C:\James\data\%JOB%\backups\%TODAY%\temp*-%TODAY%-%NOW%.bak

but when I run this the filename that I get is;

temp3.bak-20110826-01-56-PM.bak

I would like to get rid of the first .bak


Report •

Ask Question