Solved

file moving automation

Posted on 2011-03-08
8
269 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 55

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
RussPitcher earned 500 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 55

Expert Comment

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

~bp
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 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