Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have created but not complete a vbscript that can move the oldest file by last modified date(not current date). The code is the following:
Dim totFileCount,startFolder,folderdestination,objFile,totalFiles,fs
Set fso = CreateObject("Scripting.FileSystemObject")
startFolder = "C:\Documents and Settings\jhurtado\Desktop\VBS"
totFileCount = fso.GetFolder(startFolder).Files.Count
If totFileCount <= 1 Then
Wscript.Quit
End If
Set totalFiles = fso.GetFolder(startFolder)
folderdestination = "C:\Documents and Settings\jhurtado\Desktop\VBS_Old"
For Each objFile In totalFiles.Files
If objFile.DateLastModified Then
objFile.Move folderdestination & "\" & objFile.Name
End If
Next
Wscript.QuitTo give you an example I have two files, a text file and excel file. The text file have a last modified date of 1/2/2006 and the excel file have a last modified date of 1/16/2006. I want to move the oldest file to another folder (in this case the text file)to another folder and leave the excel file (in this case) intact in place. Can you help me????Thanks for your help.

Dim sourcePath,targetPath,objFile,totalFiles,fso
Set fso = CreateObject("Scripting.FileSystemObject")
sourcePath = "C:\Documents and Settings\mdamato\Desktop\VBS"If fso.GetFolder(sourcePath).Files.Count <= 1 Then
Wscript.Quit
End IfSet sourceFolder = fso.GetFolder(sourcePath)
targetPath = "C:\Documents and Settings\mdamato\Desktop\VBS_Old"Dim oldestFile, oldestDate
For Each objFile In sourceFolder.Files
If oldestFile = "" Then
Set oldestFile = objFile
Else
If objFile.DateLastModified < oldestFile.DateLastModified Then
Set oldestFile = objFile
End If
End If
NextoldestFile.Move targetPath & "\" & oldestFile.Name
Wscript.Quit
Michael J

You could also do it with this BAT:
::== move1old.bat
@echo off
set done=N
for /f "tokens=*" %%F in ('dir /b/od') do (
call :sub1 %%F )
goto :eof:sub1
if %done% equ Y goto :eof
set done=Y
echo move %*
goto :eof
:: DONE
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |