need help in dos batch..newbie here..

January 4, 2010 at 15:17:55
Specs: Windows XP
good day to everyone..

i'm know someone could help me out there about my problem.

i'm a newbie regarding dos batch scripting so i don't really know how to solve my prob..

what i need to do is to search a file in a folder and and copy it to another folder..not all files must be copied..i need to specifically pick the file, i.e.;

INSITE-PH01_1_20090715100000_001
INSITE-PH01_1_20090715100000_002
INSITE-PH01_1_20090715100000_003
INSITE-PH01_1_20090716100000_001
INSITE-PH01_1_20090716100000_002

in this case i need to copy the files with recent date, and that would be:

INSITE-PH01_1_20090716100000_001
INSITE-PH01_1_20090716100000_002

is this possible?

Any help that anyone can offer, is truly appreciated.

Thank you!

anyone needs a second chance..


See More: need help in dos batch..newbie here..

Report •


#1
January 4, 2010 at 16:13:27
Does this boil down to : copy the 2 most recent files?

or what?


=====================================
Helping others achieve escape felicity

M2


Report •

#2
January 4, 2010 at 16:18:03
I've finally solved my problem in this matter..
by this code:

@echo off
set SourcePath=d:\deck\TEST\Source
set Destination=d:\deck\TEST\20090716
set Insite=2009071610
IF NOT EXIST %Destination% GOTO NOPATH

:GETUPDATE
echo "updating local files..."
COPY /Y %SourcePath%\*%Insite%*.txt %Destination%

:NOPATH
echo "creating %Destination%..."
mkdir %Destination%
echo "copying files..."
COPY /Y %SourcePath%\*%Insite%*.txt %Destination%

but now i have a second problem..
I need to automate this..coz in this code i'm only manually encoding/changing the values of:
set Destination=d:\deck\TEST\20090716
set Insite=2009071610

20090716
YYYYMMDD
2009071610
YYYYMMDDHH

is it possible that whenever I run this batch file, the values of the ITALIC words above will automatically change depending on the date and time i run it..

thanks in advance..

-Derrick

anyone needs a second chance..


Report •

#3
January 11, 2010 at 15:35:49
try this code..

@echo off

set Hour=%time:~0,2%
if %Hour% lss 10 (set Hour=0%time:~1,1%)
set Min=%time:~3,2%
set Sec=%time:~6,2%
set FinHour=%Hour%
set Date=%date%
set FinDate=%Date:~10,4%%Date:~4,2%%Date:~7,2%
set SourcePath=d:\deck\TEST\Source 
set Destination=d:\deck\TEST\%FinDate%
set Insite=%FinDate%%FinHour%
IF NOT EXIST %Destination% GOTO NOPATH 

:GETUPDATE 
echo "updating local files..." 
COPY /Y %SourcePath%\*%Insite%*.txt %Destination% 
goto END

:NOPATH 
echo "creating %Destination%..." 
mkdir %Destination% 
echo "copying files..." 
COPY /Y %SourcePath%\*%Insite%*.txt %Destination% 
goto END

:END

i hope you understand the code..
ask me if something goes wrong or if you didn't understand the code..i'll be glad to help..

-atashinchi


Report •

Related Solutions

#4
January 11, 2010 at 17:29:48
thanks for the code..
it's just what i'm looking for..


now my problem had been solved..
thanks atashinchi..

anyone needs a second chance..


Report •

#5
January 11, 2010 at 17:32:15
no problem..
just post if you have any problems..


Report •

Ask Question