Newbie here needs help to manipulate file names
Moderator: DosItHelp
Newbie here needs help to manipulate file names
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!
Lelouch
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!
Lelouch
dirty code uses hard break:
Code: Select all
@echo off
setlocal enableextensions
set "indir=c:\in dir"
set "outdir=d:\out dir"
set "begin=INSITE-PH01_1_20"
chdir /d "%indir%"
for /f "delims=" %%f in ('dir /b/o-n %begin%????????????_???.*') do call :f "%%f"
:f
set "n=%~n1"
set "l=%n:~0,-10%"
copy /b "%l%??????_???.*" "%outdir%" &EXIT
thanks..
thanks for the help..
i'll try this one now..
i'll try this one now..
thanks..
someone gave me a code and i edited it..
and I finally solved my problem somehow..
I'll only need to change the value of the insite depending on the date that i need to copy..
and I finally solved my problem somehow..
Code: Select all
@echo off
set SourcePath=d:\deck\TEST\Source
set Destination=d:\deck\TEST\20090918
set Insite=2009091814
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%
I'll only need to change the value of the insite depending on the date that i need to copy..
re
Copy files from the last date in the name or a specific date?
specific date...
And yet, that means "14" in the Insite=2009091814
the format of:
2009091814
is
YYYYMMDDHH
Code: Select all
@echo off
setlocal enableextensions
set "SourcePath=d:\deck\TEST\Source"
set "DestinPath=d:\deck\TEST"
if "%~1"=="" (echo Need input YYYYMMDDHH, ex. %~nx0 2009091814 &exit /b)
set "Insite=%~1"
set "Day=%Insite:~0,8%"
if not "%Day%"=="%Insite:~0,-2" (echo Wrong input. Need 10 simbols, ex. 2009091814 &exit /b)
set "Destination=%DestinPath%\%Day%"
if exist %Destination% goto :getupdate
:nopath
echo "Creating %Destination%..."
mkdir "%Destination%"
:getupdate
echo "Copying files..."
copy /y "%SourcePath%\*%Insite%*.txt" "%Destination%" >nul
Untested
thanks for the code..
hehe..i didn't understand some of the code..
sorry i'm new in batch scripting..
by the way, i manage to edit my previous code to achieve what i want..
here's the code of what i've done:
this is the final code of my small project..
!k
-thanks for the codes and responses..it's been a great help for me..
sorry for my english
hehe..i didn't understand some of the code..
sorry i'm new in batch scripting..
by the way, i manage to edit my previous code to achieve what i want..
here's the code of what i've done:
Code: Select all
@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 FinHr=%Hour%
set Dte=%date%
set FinDte=%Dte:~10,4%%Dte:~4,2%%Dte:~7,2%
set SourcePath=d:\deck\TEST\Source
set Destination=d:\deck\TEST\%FinDte%
set Insite=%FinDte%%FinHr%
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
this is the final code of my small project..
!k
-thanks for the codes and responses..it's been a great help for me..
sorry for my english