Link to home
Start Free TrialLog in
Avatar of columbusclinic

asked on

file moving automation

I have an issue where everyday i have to move files from one folder to another with that days date ex

i move the files from \\server1\Transcription\Completed Voice Files
to the following    \\server1\transctiption\archived voice files\ todays date

i am looking for a way to automate this process and do not know where to start

please help
Avatar of Bill Prew
Bill Prew

I think this VBS script should do what you want.  Save as a VBS and run, adjust paths if needed.

' Define location of files to move
sBaseFolder = "\\server1\Transcription\Completed Voice Files\*.*"

' Build location to move files to, including dated folder (YYYYMMDD)
strDay = Right("0" & Day(Now), 2)
strMonth = Right("0" & Month(Now), 2)
strYear = Year(Now)
sDestFolder = "\\server1\transctiption\archived voice files\" & strYear & StrMonth & strDay & "\"

' Make sure that dated folder exists, and move files to it
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strDestFolder) Then objFSO.CreateFolder(strDestFolder)
oFSO.MoveFile strBaseFolder, strDestFolder

Open in new window

This should do it:

Dim strSource, strDest, objFSO, objFile

strSource = "\\server1\Transcription\Completed Voice Files"
strDest = "\\server1\transctiption\archived voice files\" & SortableDate() & "\"

Set objFSO = CreateObject("Scripting.FileSystemObject")

WScript.Echo "Destination folder = " & strDest
For Each objFile In objFSO.GetFolder(strSource).Files
	WScript.Echo "  Moving file " & objFile.Name
	objFSO.MoveFile objFile.Path, strDest & objFile.Name

Function SortableDate
	Dim strTemp
	'Generate a sortable date: YYYY-MM-DD
	strTemp = Year(Now)	
	If Len(Month(Now)) = 1 Then
		strTemp = strTemp & "-0" & Month(Now)
		strTemp = strTemp & "-" & Month(Now)
	End If
	If Len(Day(Now)) = 1 Then
		strTemp = strTemp & "-0" & Day(Now)
		strTemp = strTemp & "-" & Day(Now)
	End If
	SortableDate = strTemp
End Function

Open in new window

The SortableDate functions generates a date in the YYYY-MM-DD format so it sorts well in explorer.
Curses - beaten by 1 minute!
Avatar of RussPitcher
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of columbusclinic


Russ,  great script works great, but it makes me acknowledge each file that is being moved and the source and destination folders, can that be changed?
Ah, you're running it with Wscript (graphical, double-clicking the file).  As a fully paid up geek my scripts are all written to use CScript on the command line, and I like to see lots of output - makes me feel important or something :)

If you want to be able to double-click it then remove the Wcript.echo lines (lines 8 and 11 in the last example).
Great work, thank you for your help
Just curious, what functionality was missing from my initial solution?