Computer Learning Zone CLZ Access Excel Word Windows

Knowledge will bring you the opportunity to make a difference.

-Claire Fagin
 
Home   Courses   Seminars   Templates   Help   TechHelp   Forums   Contact   Join   Order   Logon  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
VBScript

Rename and archive a File

How to rename and archive a file.

In this tip you will learn how to Rename a file and move it to another folder to archive it.

Add this script to the folder with the file you wish to Archive

Create a folder called archive

Then amend a few variables of the below code: path.

Firstly the filename to whatever your file is called.

filename = "Report.csv"

Now the filename you wish to then call the archive and the file extenstion to match your current file.

fso.MoveFile filename, path & "archive\Report " & createdate & ".csv"

	' ---------------------------------------------------------------------
	' Rename a file and move it
	' Rename it to datetime and move to archive.
	'
	' Created by Alex Hedley
	' Date Created: 28/01/2013
	' Date Updated: ##/##/####
	'
	' Required Refs: 
	' ---------------------------------------------------------------------
	Dim fso 
	Set fso = CreateObject("Scripting.FileSystemObject") 
	 
	Dim filename
	'filename = "testfile.txt"
	filename = "Report.csv"
	 
	Dim path
	path = "ADD YOUR PATH HERE"
	 
	Dim demofile
	Set demofile = fso.GetFile(path & filename)
	createdate = demofile.DateCreated
	 
	' Format DateTime from dd/mm/yyyy hh:nn:ss => yyyymmdd_hhnn
	'createdate = year(createdate) & month(createdate) & _
	'	day(createdate) & "_" & hour(createdate) & minute(createdate)
	
	'Build up the Date
	Dim yearNum, monthNum, dayNum, hourNum, minNum
	yearNum = year(createdate)
	monthNum = month(createdate)
	dayNum = day(createdate)
	hourNum = hour(createdate)
	minNum = minute(createdate)
	 
	' 0s are going, add them back in.
	If len(monthNum) < 2 Then monthNum = "0" & monthNum
	If len(dayNum) < 2 Then dayNum = "0" & dayNum
	If len(hourNum) < 2 Then hourNum = "0" & hourNum
	If len(minNum) < 2 Then minNum = "0" & minNum
	' Join it up
	createdate = yearNum & monthNum & dayNum & "_" & hourNum & minNum
	 
	' Add the CreateDate and move to the archive
	fso.MoveFile filename, path & "archive\Report " & createdate & ".csv"
	 
	Msgbox "Done"
	
Download Source

Source

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn