Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB script to copy files from one folder to another folder

Status
Not open for further replies.

madhuadavi

Technical User
Jul 8, 2009
3
IN
Hi,

I wanted one VB script which has to do the following thing.

1) there will be one log folder.
in that log folder every day log files will be creating, so i wanted to make automation for this like the script has to search logfiles which are recently created and it has to copy those files to another directory..

PLZ some one help me in this..
 
Hello,,

Sorry i didnt get any thing from that link.. even i dont know VB scripting and coding..

Some one plz help me in this.. i need working VB script..
 

numDays = 3

strSource = "C:\Documents and Settings\madhuk\Desktop\folder1"

strDest = "C:\Documents and Settings\madhuk\Desktop\folder1"



Set objfso = CreateObject("Scripting.FileSystemObject")

If objfso.FolderExists(strPath) Then

Set objFolder = objfso.GetFolder(strPath)

'Call CheckFolder(objFolder, numDays, True)

Else

'WScript.Echo "The specified folder", strPath, "does not exist"
Call CopyOldFile(objFile, numDays)

End If



'Sub CheckFolder(objFolder, numDays, bRecurse)

' Set colFiles = objFolder.Files

'If colFiles.Count > 0 Then

'For Each objFile In colFiles

'Call CopyOldFile(objFile, numDays)

'Next

'Else

'WScript.Echo "No files in folder", objFolder.Path

'End If

'If bRecurse Then

' Set colSubfolders = objFolder.SubFolders

'If colSubfolders.Count > 0 Then

'For Each SubFolder In colSubfolders

' CheckFolder SubFolder, numDays, True

'Next

'End If

'End If

'End Sub



Sub CopyOldFile(objFile, numDays)

On Error Resume Next

Err.Clear

dateFile = objFile.DateLastModified

dateToday = Now()

If dateFile <= dateToday Then

daysOld = dateToday - dateFile

If daysOld > numDays Then

strFile = objFile.Path

objFile.Attributes = 0

objFile.Copy strDest

If Err.number <> 0 Then

WScript.Echo Err.number, Err.Description, Err.Source, strFile

Else

WScript.Echo strFile, "copied"

End If

End If

Else

WScript.Echo "Incorrect date stamp in", strFile

End If

End Sub




I got this above code.. but i tried its not copying the files..
 
The code you've got there is a long way away from working in it's current state I'm afraid.

Have a look at markdmac's post in thread329-1548867, it doesn't do exactly what you want but is easily changed to meet your requirements (this is the ethos of TT, we're here to help, not provide free full code solutions).

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top