[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

file moving automation

Posted on 2011-03-08
8
Medium Priority
?
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 58

Expert Comment

by:Bill Prew
ID: 35069255
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
ID: 35069261
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
ID: 35069265
Curses - beaten by 1 minute!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Accepted Solution

by:
RussPitcher earned 2000 total points
ID: 35069286
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
 

Author Comment

by:columbusclinic
ID: 35069513
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
ID: 35069558
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
ID: 35069653
Great work, thank you for your help
0
 
LVL 58

Expert Comment

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

~bp
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 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