Solved

file moving automation

Posted on 2011-03-08
8
231 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:columbusclinic
  • 4
  • 2
  • 2
8 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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

~bp
0
 
LVL 3

Expert Comment

by:RussPitcher
Comment Utility
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
Next

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)
	Else
		strTemp = strTemp & "-" & Month(Now)
	End If
	If Len(Day(Now)) = 1 Then
		strTemp = strTemp & "-0" & Day(Now)
	Else
		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.
0
 
LVL 3

Expert Comment

by:RussPitcher
Comment Utility
Curses - beaten by 1 minute!
0
 
LVL 3

Accepted Solution

by:
RussPitcher earned 500 total points
Comment Utility
Missed  a line as well <embarrased>

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
If Not objFSO.FolderExists(strDest) Then objFSO.CreateFolder(strDest)
For Each objFile In objFSO.GetFolder(strSource).Files
	WScript.Echo "  Moving file " & objFile.Name
	objFSO.MoveFile objFile.Path, strDest & objFile.Name
Next

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)
	Else
		strTemp = strTemp & "-" & Month(Now)
	End If
	If Len(Day(Now)) = 1 Then
		strTemp = strTemp & "-0" & Day(Now)
	Else
		strTemp = strTemp & "-" & Day(Now)
	End If
	
	SortableDate = strTemp
End Function
	

Open in new window

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:columbusclinic
Comment Utility
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?
0
 
LVL 3

Expert Comment

by:RussPitcher
Comment Utility
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).
0
 

Author Closing Comment

by:columbusclinic
Comment Utility
Great work, thank you for your help
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Just curious, what functionality was missing from my initial solution?

~bp
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

9 Experts available now in Live!

Get 1:1 Help Now