Solved

file moving automation

Posted on 2011-03-08
8
251 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 53

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 53

Expert Comment

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

~bp
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

772 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