Solved

Batch script for win2000 that moves files

Posted on 2007-04-02
46
199 Views
Last Modified: 2010-04-16
Hello,
I have never written any batch files before but I need to move files which are older than 2 days from one directory to another on a windows 2000 server. Can anyone help me out with that?
THanks,
Dee
0
Comment
Question by:indacrypt
  • 26
  • 19
46 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18836370
This should do it - if you're looking for a vbscript method...


Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOutputFile:Set objOutputFile = objFSO.CreateTextFile("C:\FilesMoved.log")
Dim dtOld
strSourceFolder = "C:\Testing\"
strTargetFolder = "C:\TargetFolder\"
With objOutputFile
  .WriteLine "==========================="
  .WriteLine "Relocation summary for " & Date
  .WriteLine "=-=-=-=-=-=-=-=-=-=-=-=-=-="
  .WriteLine
End With

'intDel is the number of days old you want to check for.
intDel = 2
dtOld = DateAdd("d", -intDel, Date)

ProcessFolder objFSO.GetFolder(strSourceFolder)

With objOutputFile
  .WriteLine
  .WriteLine "Process completed at " & Now
  .WriteLine "==========================="
  .Close
End With

Set objOutputFile = Nothing
Set objFSO = Nothing
wscript.quit

Sub ProcessFolder(strSource)
  ProcessFiles strSource
  For Each fld In strSource.SubFolders
    ProcessFolder fld
  Next
End Sub

Sub ProcessFiles(strSrc)
  For Each file In strSrc.Files
    objOutputFile.WriteLine file.Path & " was relocated at " & Now
    objFSO.MoveFile file.Path, strTargetFolder
  End If
  Next
End Sub
0
 

Author Comment

by:indacrypt
ID: 18836430
umm no...just using windows commands... thanks very much though
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18836539
@echo off

setlocal

REM ** Set debug= to activate code
set debug=echo

if "%~2"=="" echo Usage: %0 sourceDirectory destinationDirectory&goto :EOF
if not exist "%~1" echo %~1 does not exist&goto :EOF
if not exist "%~2" echo %~2 does not exist&goto :EOF

set srcDir=%~1
set destDir=%~2

REM ** This makes sure that the trailing backslash if specified is removed
REM ** I don't believe that works in 2000, so you'll have to make sure
REM ** that you don't specify a trailing backslash for the destination
REM if "%destDir:~-1%"=="\" set destDir=%destDir:~0,-1%

call :GETDATEPARTS "%date%"

call :SUBTRACTDAYS 2

set cutOff=%yy%%mm%%dd%

pushd "%srcDir%"

for /f "tokens=*" %%a in ('dir /b /a-d "%srcDir%" 2^>NUL') do call :PROCESS "%%a" %%~ta

popd

goto :EOF

:PROCESS

call :GETDATEPARTS %~2

%debug% if /i "%yy%%mm%%dd%" LSS "%cutOff%" move "%~1" "%destDir%\%~1"

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF

:SUBTRACTDAYS

set dayCnt=%1

if "%dayCnt%"=="" set dayCnt=1

REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100

:CHKDAY

if /I %dd% GTR 0 goto DONESUBTRACT

set /A mm=%mm% - 1

if /I %mm% GTR 0 goto ADJUSTDAY

set /A mm=12
set /A yy=%yy% - 1

:ADJUSTDAY

if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through

:SET31

set /A dd=31 + %dd%

goto CHKDAY

:SET30

set /A dd=30 + %dd%

goto CHKDAY

:LEAPCHK

set /A tt=%yy% %% 4

if not %tt%==0 goto SET28

set /A tt=%yy% %% 100

if not %tt%==0 goto SET29

set /A tt=%yy% %% 400

if %tt%==0 goto SET29

:SET28

set /A dd=28 + %dd%

goto CHKDAY

:SET29

set /A dd=29 + %dd%

goto CHKDAY

:DONESUBTRACT

if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%

goto :EOF

Good Luck,
Steve
0
 

Author Comment

by:indacrypt
ID: 18836593
oh wow....didnt realise the script would be so long!! Ill try it ...ill have to give it two days to try it coz i manually psuhed the files over today. Will let you know.
Thanks!!
0
 

Author Comment

by:indacrypt
ID: 18883040
i realised I dont have the expertise to modify that script so IM not going to be using either of these. Thanks!
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18884108
Don't have to modify mine all you have to do is run it with the parameters you specify. Run it without parameters to get the usage.

0
 

Author Comment

by:indacrypt
ID: 18884161
Hi Steve...what parameters would I be using..do you mean i just rename srcDir and destDir?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18884174
If you named the batch file MyMoveFile.bat you'd say:

MyMoveFile "c:\temp" "d:\temp"
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18884186
Here's the version that actually moves files:

@echo off

setlocal

REM ** Set debug= to activate code
set debug=

if "%~2"=="" echo Usage: %0 sourceDirectory destinationDirectory&goto :EOF
if not exist "%~1" echo %~1 does not exist&goto :EOF
if not exist "%~2" echo %~2 does not exist&goto :EOF

set srcDir=%~1
set destDir=%~2

REM ** This makes sure that the trailing backslash if specified is removed
REM ** I don't believe that works in 2000, so you'll have to make sure
REM ** that you don't specify a trailing backslash for the destination
REM if "%destDir:~-1%"=="\" set destDir=%destDir:~0,-1%

call :GETDATEPARTS "%date%"

call :SUBTRACTDAYS 2

set cutOff=%yy%%mm%%dd%

pushd "%srcDir%"

for /f "tokens=*" %%a in ('dir /b /a-d "%srcDir%" 2^>NUL') do call :PROCESS "%%a" %%~ta

popd

goto :EOF

:PROCESS

call :GETDATEPARTS %~2

%debug% if /i "%yy%%mm%%dd%" LSS "%cutOff%" move "%~1" "%destDir%\%~1"

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF

:SUBTRACTDAYS

set dayCnt=%1

if "%dayCnt%"=="" set dayCnt=1

REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100

:CHKDAY

if /I %dd% GTR 0 goto DONESUBTRACT

set /A mm=%mm% - 1

if /I %mm% GTR 0 goto ADJUSTDAY

set /A mm=12
set /A yy=%yy% - 1

:ADJUSTDAY

if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through

:SET31

set /A dd=31 + %dd%

goto CHKDAY

:SET30

set /A dd=30 + %dd%

goto CHKDAY

:LEAPCHK

set /A tt=%yy% %% 4

if not %tt%==0 goto SET28

set /A tt=%yy% %% 100

if not %tt%==0 goto SET29

set /A tt=%yy% %% 400

if %tt%==0 goto SET29

:SET28

set /A dd=28 + %dd%

goto CHKDAY

:SET29

set /A dd=29 + %dd%

goto CHKDAY

:DONESUBTRACT

if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%

goto :EOF
0
 

Author Comment

by:indacrypt
ID: 18884523
when i try saying movelogs "D:\<path here>" "w:\" (w is a mapped network drive, no password required), it gives me an error saying the path on the D drive is invalid..!
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18884610
What exactly does it say?

Does it say:

d:\yourpath does not exist

Or some other message?

Can you reveal the path so that I can check it out?

Here's a version with debug information. Please report back what it says when you run this code:

@echo off

setlocal

REM ** Set debug= to activate code
set debug=

if "%~2"=="" echo Usage: %0 sourceDirectory destinationDirectory&goto :EOF
if not exist "%~1" echo %~1 does not exist&goto :EOF
if not exist "%~2" echo %~2 does not exist&goto :EOF

set srcDir=%~1
set destDir=%~2

REM ** This makes sure that the trailing backslash if specified is removed
REM ** I don't believe that works in 2000, so you'll have to make sure
REM ** that you don't specify a trailing backslash for the destination
REM if "%destDir:~-1%"=="\" set destDir=%destDir:~0,-1%

call :GETDATEPARTS "%date%"

call :SUBTRACTDAYS 2

set cutOff=%yy%%mm%%dd%

echo curOff=%cutOff%
echo srcDir=%srdDir%
echo destDir=%destDir%

pushd "%srcDir%"

echo After pushd command...

for /f "tokens=*" %%a in ('dir /b /a-d "%srcDir%" 2^>NUL') do call :PROCESS "%%a" %%~ta

After for command...

popd

echo After popd command...

goto :EOF

:PROCESS

call :GETDATEPARTS %~2

%debug% if /i "%yy%%mm%%dd%" LSS "%cutOff%" move "%~1" "%destDir%\%~1"

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF

:SUBTRACTDAYS

set dayCnt=%1

if "%dayCnt%"=="" set dayCnt=1

REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100

:CHKDAY

if /I %dd% GTR 0 goto DONESUBTRACT

set /A mm=%mm% - 1

if /I %mm% GTR 0 goto ADJUSTDAY

set /A mm=12
set /A yy=%yy% - 1

:ADJUSTDAY

if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through

:SET31

set /A dd=31 + %dd%

goto CHKDAY

:SET30

set /A dd=30 + %dd%

goto CHKDAY

:LEAPCHK

set /A tt=%yy% %% 4

if not %tt%==0 goto SET28

set /A tt=%yy% %% 100

if not %tt%==0 goto SET29

set /A tt=%yy% %% 400

if %tt%==0 goto SET29

:SET28

set /A dd=28 + %dd%

goto CHKDAY

:SET29

set /A dd=29 + %dd%

goto CHKDAY

:DONESUBTRACT

if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%

goto :EOF
0
 

Author Comment

by:indacrypt
ID: 18884705
C:\>movelogs "D:\Program Files\KANA\Response Server\shareddir\logs\" "W:\"
curOff=20070408
srcDir=
destDir=W:\
After pushd command...
'After' is not recognized as an internal or external command,
operable program or batch file.
After popd command...

C:\>
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18884890
I forgot a echo statement on the one debugging line:

After for command...

Should be:

echo After for command...

I don't see any problems there. Where is the error about d:?
0
 

Author Comment

by:indacrypt
ID: 18889040
Umm...well it doesnt show the src directory it just says "srcDIr =", and now even tho it runs without any errors, it hasnt moved any of the files either...
0
 

Author Comment

by:indacrypt
ID: 18889059
the batchfile doesnt have to be located on the same drive as the srcDir does it?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18889091
No it doesn't have to exist in the same directory. Here's another debug batch. Please post back results:

@echo off

setlocal

REM ** Set debug= to activate code
set debug=

if "%~2"=="" echo Usage: %0 sourceDirectory destinationDirectory&goto :EOF
if not exist "%~1" echo %~1 does not exist&goto :EOF
if not exist "%~2" echo %~2 does not exist&goto :EOF

set srcDir=%~1
set destDir=%~2

REM ** This makes sure that the trailing backslash if specified is removed
REM ** I don't believe that works in 2000, so you'll have to make sure
REM ** that you don't specify a trailing backslash for the destination
REM if "%destDir:~-1%"=="\" set destDir=%destDir:~0,-1%

call :GETDATEPARTS "%date%"

call :SUBTRACTDAYS 2

set cutOff=%yy%%mm%%dd%

echo curOff=%cutOff%
echo srcDir=%srdDir%
echo destDir=%destDir%

pushd "%srcDir%"

for /f "tokens=*" %%a in ('dir /b /a-d "%srcDir%" 2^>NUL') do call :PROCESS "%%a" %%~ta

popd

goto :EOF

:PROCESS

call :GETDATEPARTS %~2

echo if /i "%yy%%mm%%dd%" LSS "%cutOff%" move "%~1" "%destDir%\%~1"

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF

:SUBTRACTDAYS

set dayCnt=%1

if "%dayCnt%"=="" set dayCnt=1

REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100

:CHKDAY

if /I %dd% GTR 0 goto DONESUBTRACT

set /A mm=%mm% - 1

if /I %mm% GTR 0 goto ADJUSTDAY

set /A mm=12
set /A yy=%yy% - 1

:ADJUSTDAY

if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through

:SET31

set /A dd=31 + %dd%

goto CHKDAY

:SET30

set /A dd=30 + %dd%

goto CHKDAY

:LEAPCHK

set /A tt=%yy% %% 4

if not %tt%==0 goto SET28

set /A tt=%yy% %% 100

if not %tt%==0 goto SET29

set /A tt=%yy% %% 400

if %tt%==0 goto SET29

:SET28

set /A dd=28 + %dd%

goto CHKDAY

:SET29

set /A dd=29 + %dd%

goto CHKDAY

:DONESUBTRACT

if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%

goto :EOF
0
 

Author Comment

by:indacrypt
ID: 18889147
if /i "20070410" LSS "20070409" move "log20070410_213008.xml" "W:\log20070410_2
3008.xml"
if /i "20070410" LSS "20070409" move "log20070410_213444.xml" "W:\log20070410_2
3444.xml"
if /i "20070410" LSS "20070409" move "log20070410_214029.xml" "W:\log20070410_2
4029.xml"
if /i "20070410" LSS "20070409" move "log20070410_214441.xml" "W:\log20070410_2
4441.xml"
if /i "20070410" LSS "20070409" move "log20070410_214911.xml" "W:\log20070410_2
4911.xml"
if /i "20070410" LSS "20070409" move "log20070410_215448.xml" "W:\log20070410_2
5448.xml"
if /i "20070410" LSS "20070409" move "log20070410_215932.xml" "W:\log20070410_2
5932.xml"
if /i "20070410" LSS "20070409" move "log20070410_220332.xml" "W:\log20070410_2
0332.xml"
if /i "20070410" LSS "20070409" move "log20070410_220651.xml" "W:\log20070410_2
0651.xml"
if /i "20070410" LSS "20070409" move "log20070410_221120.xml" "W:\log20070410_2
1120.xml"
if /i "20070410" LSS "20070409" move "log20070410_221449.xml" "W:\log20070410_2
1449.xml"
if /i "20070410" LSS "20070409" move "log20070410_221912.xml" "W:\log20070410_2
1912.xml"
if /i "20070410" LSS "20070409" move "log20070410_222410.xml" "W:\log20070410_2
2410.xml"
if /i "20070410" LSS "20070409" move "log20070410_222758.xml" "W:\log20070410_2
2758.xml"
if /i "20070410" LSS "20070409" move "log20070410_223113.xml" "W:\log20070410_2
3113.xml"
if /i "20070410" LSS "20070409" move "log20070410_223611.xml" "W:\log20070410_2
3611.xml"
if /i "20070410" LSS "20070409" move "log20070410_224006.xml" "W:\log20070410_2
4006.xml"
0
 

Author Comment

by:indacrypt
ID: 18889152
i couldnt capture the first half of the debug....coz it started printing thisout...but again, none of the files have really been moved..like the names of the files that it mentions, are still in the src directory on the D drive
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18889520
Look's like all of the files I can see were updated 4/10/2007. The compare date is 4/9/2007.

I do a less than comparision of:

if 4/10/2007 LSS 4/9/2007 Do the move

None of the files meet the requirement.
0
 

Author Comment

by:indacrypt
ID: 18889602
But I need to move the files for the last 2 days....so I need to move files for the 9th and 10th..
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 125 total points
ID: 18889751
Sorry my mistake :)

@echo off

setlocal

REM ** Set debug= to activate code
set debug=

if "%~2"=="" echo Usage: %0 sourceDirectory destinationDirectory&goto :EOF
if not exist "%~1" echo %~1 does not exist&goto :EOF
if not exist "%~2" echo %~2 does not exist&goto :EOF

set srcDir=%~1
set destDir=%~2

REM ** This makes sure that the trailing backslash if specified is removed
REM ** I don't believe that works in 2000, so you'll have to make sure
REM ** that you don't specify a trailing backslash for the destination
REM if "%destDir:~-1%"=="\" set destDir=%destDir:~0,-1%

call :GETDATEPARTS "%date%"

call :SUBTRACTDAYS 2

set cutOff=%yy%%mm%%dd%

echo curOff=%cutOff%
echo srcDir=%srdDir%
echo destDir=%destDir%

pushd "%srcDir%"

for /f "tokens=*" %%a in ('dir /b /a-d "%srcDir%" 2^>NUL') do call :PROCESS "%%a" %%~ta

popd

goto :EOF

:PROCESS

call :GETDATEPARTS %~2

if /i "%yy%%mm%%dd%" GEQ "%cutOff%" move "%~1" "%destDir%\%~1"

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF

:SUBTRACTDAYS

set dayCnt=%1

if "%dayCnt%"=="" set dayCnt=1

REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100

:CHKDAY

if /I %dd% GTR 0 goto DONESUBTRACT

set /A mm=%mm% - 1

if /I %mm% GTR 0 goto ADJUSTDAY

set /A mm=12
set /A yy=%yy% - 1

:ADJUSTDAY

if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through

:SET31

set /A dd=31 + %dd%

goto CHKDAY

:SET30

set /A dd=30 + %dd%

goto CHKDAY

:LEAPCHK

set /A tt=%yy% %% 4

if not %tt%==0 goto SET28

set /A tt=%yy% %% 100

if not %tt%==0 goto SET29

set /A tt=%yy% %% 400

if %tt%==0 goto SET29

:SET28

set /A dd=28 + %dd%

goto CHKDAY

:SET29

set /A dd=29 + %dd%

goto CHKDAY

:DONESUBTRACT

if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%

goto :EOF
0
 

Author Comment

by:indacrypt
ID: 18889886
GEQ..ah okie...i tried GTE lol. This one gets stuck after it echoes the destDir tho...:( THanks for your prompt replies. Much appreciated!
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18889993
Where it echo's destDir?

My last solution doesn't echo destDir... what are you talking about?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:indacrypt
ID: 18890011
echo curOff=%cutOff%
echo srcDir=%srdDir%
echo destDir=%destDir%
0
 

Author Comment

by:indacrypt
ID: 18890019
C:\>movelogstest "D:\Program Files\KANA\Response Server\shareddir\logs" "W:"
curOff=20070409
srcDir=
destDir=W:
if /i "20070410" GEQ "20070409" move "log20070410_160041.xml" "W:\log20070410_16
0041.xml"
if /i "20070410" GEQ "20070409" move "log20070410_160312.xml" "W:\log20070410_16
0312.xml"
if /i "20070410" GEQ "20070409" move "log20070410_160539.xml" "W:\log20070410_16
0539.xml"
if /i "20070410" GEQ "20070409" move "log20070410_160810.xml" "W:\log20070410_16
0810.xml"
if /i "20070410" GEQ "20070409" move "log20070410_161008.xml" "W:\log20070410_16
1008.xml"
if /i "20070410" GEQ "20070409" move "log20070410_161309.xml" "W:\log20070410_16
1309.xml"
if /i "20070410" GEQ "20070409" move "log20070410_161517.xml" "W:\log20070410_16
1517.xml"
if /i "20070410" GEQ "20070409" move "log20070410_161705.xml" "W:\log20070410_16
1705.xml"
if /i "20070410" GEQ "20070409" move "log20070410_161932.xml" "W:\log20070410_16
1932.xml"
if /i "20070410" GEQ "20070409" move "log20070410_162238.xml" "W:\log20070410_16
2238.xml"
if /i "20070410" GEQ "20070409" move "log20070410_162436.xml" "W:\log20070410_16
2436.xml"
if /i "20070410" GEQ "20070409" move "log20070410_162726.xml" "W:\log20070410_16
2726.xml"
if /i "20070410" GEQ "20070409" move "log20070410_163024.xml" "W:\log20070410_16
3024.xml"
if /i "20070410" GEQ "20070409" move "log20070410_163300.xml" "W:\log20070410_16
3300.xml"
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18890037
Can you run the most recent version I published?
0
 

Author Comment

by:indacrypt
ID: 18890184
thats the one....i posted the above results from that. ijust echoed the GEQ line
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18890256
Okay, and it stops or hangs up you say? When does it do that?
0
 

Author Comment

by:indacrypt
ID: 18890259
it stops soon after it prints the "destDIr=" line
0
 

Author Comment

by:indacrypt
ID: 18890262
sorry..it hangs soon after that line.not stops
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18890278
I'm sorry but the code I most recently posted doesn't echo:

destDIr=

Please post the code you are running.
0
 

Author Comment

by:indacrypt
ID: 18891306
it looks like it worked!! sorry..there were just too man files to move i guess and i thought it had hung becoz nothing was showing up ion the dest dir.! i see that theyre there now tho. THaaank you!!
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18891592
Glad it worked :)
0
 

Author Comment

by:indacrypt
ID: 18892413
To run this as a scheduled task, can i use the scheduler in windows and then in the "Run" box I just enter "c:\movelogs "D:.." "w:""
?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18892500
You could do that, but you might get into trouble access network resources under the default system account. You'll want to specify run as and set it to a domain user, like yourself. Also, you might to better to use a UNC instead of a mapped drive. Like this:

c:\movelogs d:\yourdir \\server1\share1\directory

0
 

Author Comment

by:indacrypt
ID: 18897264
c:\movelogs d:\yourdir \\server1\share1\directory.. here movelogs in the name of my batch file..so are you saying i just add the source and destination directories after that? (like  i do from the command prompt)...not sure what a UNC is..sorry!
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18897295
Basically you are referencing the network resource without the mapped drive.

Type net use and it will show you what the drive making is.
0
 

Author Comment

by:indacrypt
ID: 18897399
thanks a TON steve!
0
 

Author Comment

by:indacrypt
ID: 18897407
actually..that doesnt work on the win2000 machine :(
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18897803
What doesn't work?
0
 

Author Comment

by:indacrypt
ID: 18897951
net use. I'mmoving the files to the root directory of the mapped drive, so I didnt quite follow what you meant by  c:\movelogs d:\yourdir \\server1\share1\directory..
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18898006
Net use works on 2000 and XP.

You'd only need to use the UNC (\\server\etc...) if you were accessing a network resource through a mapped drive in a scheduled task.

The problem is that you can't be sure that w: or whatever will be mapped when the scheduled task is run. Do you understand that?
0
 

Author Comment

by:indacrypt
ID: 18898515
Yep i understood that:) wasnt sure how that UNC works!
0
 

Author Comment

by:indacrypt
ID: 18898524
aaah...never mind!!! i got what youre saying...youre sayign istead of just saying w: which is the mapped drive, provide the entire path for the mapped drive..correct?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18898552
That is correct :)
0
 

Author Comment

by:indacrypt
ID: 18899070
thanks:)..again!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now