Solved

Regarding Windows/Dos scripting in WIN2K

Posted on 2003-12-04
2
506 Views
Last Modified: 2010-04-13
Hello,

I have some files in this format

testss_db_200312041101.BAK
ts_db_200312030901.bak
abcsscscscs_db_200312030707.BAK


Is there a way i can write a script to go through all the files in a particular directory
and get that datetime part (200312041101)

Thanks in Advance.
0
Comment
Question by:schinni
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 75 total points
ID: 9881164
This extracts your timestamps in the current directory. For your convenience (if you should need it), it extracts the date and time as well.

====8<----[GetTimeStamp.cmd]----
@echo off
setlocal
for /f "tokens=*" %%a in ('dir *.bak /b /a:-d') do call :process "%%a"
goto leave

:process
set FileName=%~1
set FileNameNoExt=%~n1
set TimeStamp=%FileNameNoExt:~-12%
set FileYY=%TimeStamp:~0,4%
set FileMM=%TimeStamp:~4,2%
set FileDD=%TimeStamp:~6,2%
set FileHour=%TimeStamp:~8,2%
set FileMin=%TimeStamp:~10,2%
echo [%FileName%]
echo   +--Timestamp: %TimeStamp%
echo   +--File date: %FileMM%/%FileDD%/%FileYY%
echo   +--File time: %FileHour%:%FileMin%
goto :eof

:leave
====8<----[GetTimeStamp.cmd]----
0
 

Author Comment

by:schinni
ID: 10257993
Hi obda,


Can you help me with this
Hello,
I  have to  delete files older than 3days
My files end with this extension 2000402021211..etc
so i am getting the extension and comparing with
currentdate -3


basically i want to do %FileDD%/ -3

rem @echo off
setlocal


for /f "tokens=1,2" %%u in ('date /t') do set d=%%v
for /f "tokens=5-8 delims=:., " %%a in ('echo:^|time') do (
set hh=%%a
set mn=%%b
set ss=%%c
set cs=%%d
)

set curtim=%d:~6,4%%d:~0,2%%d:~3,2%%hh%%mn%
:: Current Date -3

I am doing this because of octal 8 and 9

if %d:~3,2% LSS 10 set /a dat = %d:~4,1%-3
if %d:~3,2% GTR 7 set /a dat = %d:~4,1%-3
if %d:~3,2% GTR 09 set /a dat = %d:~3,2%-3
if %d:~3,2% LSS 8 set /a dat = %d:~3,2%-3



if %dat% LSS 10 set dat=0%dat%
if %hh% LSS 10 set hh=0%hh%

set timestr=%d:~6,4%%d:~0,2%%dat%%hh%%mn%

I  am doing this to getting the currentdate and subtracting date varaible with -3
it works great but when it's from day 1 to 3 of the month i am getting negative variables
and also one more thing is
cuurent date is 200402021111 i am subtracting 02 -3 which i am getting -1
and the whole doesn't work correctly ..

can anybody help me with the workaround

Thanks in Advance!

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Print Server: NT to 2008 10 594
Migrate DHCP from server 2000 to 2008 1 641
Windows Foriegn Disk 3 141
Windows Services - Run a Program Grey Out 3 98
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question