Posts Tagged ‘file’

Mass updating SaveAs field in outlook contacts

Tuesday, January 13th, 2009

If you ever had a problem that you needed to change SaveAs field in contacts in Microsoft Outlook on all contacts here is one small VB script that parse everything for you.

The only thing that you need to do is uncomment proper part of the code which is strFileAs.

In my case I wanted to everything be formated as Firstname Lastname instead of reverse way that is default in outlook.

Press alt+f11 to open vb editor, paste the code, edit strFileAs and press F5 to run it. When it’s done you will have your contacs sorted and changed in your way.

P.S. removing comment in vb means removing sign ‘ in front of the line or text, so if you want to comment something write ‘ in front of the line. In this case you will comment out strFileAs = .FullName part if you don’t want to be Firstname Lastname format and uncomment some other strFileAs line that fits your needs.

Public Sub ChangeFileAs()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objContact As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim objContactsFolder As Outlook.MAPIFolder
Dim obj As Object
Dim strFirstName As String
Dim strLastName As String
Dim strFileAs As String

On Error Resume Next

Set objOL = CreateObject(“Outlook.Application”)
Set objNS = objOL.GetNamespace(“MAPI”)
Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)
Set objItems = objContactsFolder.Items

For Each obj In objItems
‘Test for contact and not distribution list
If obj.Class = olContact Then
Set objContact = obj

With objContact
‘ Uncomment the  strFileAs line for the desired format

‘Lastname, Firstname (Company) format
‘ strFileAs = .FullNameAndCompany

‘Firstname Lastname format
strFileAs = .FullName

‘Lastname, Firstname format
‘ strFileAs = .LastNameAndFirstName

‘Company name only
‘ strFileAs = .CompanyName

‘Companyname (Lastname, Firstname)
‘ strFileAs = .CompanyAndFullName

.FileAs = strFileAs

.Save
End With
End If

Err.Clear
Next

Set objOL = Nothing
Set objNS = Nothing
Set obj = Nothing
Set objContact = Nothing
Set objItems = Nothing
Set objContactsFolder = Nothing
End Sub

Creating simple cleanup scripts on Windows 2003

Monday, November 10th, 2008

Here is one short tip. If you had problem with old log files that are being held on system after too much time and wanted to delete all of them automatically here is explanation how to do it.

  1. open notepad
  2. write this line in it Forfiles -p “c:\temp” -s -m *.log -d -14 -c “Cmd /C del @FILE”
  3. save file and then change it extension from .txt to .bat

So here we have batch file created that will do following:

  • find all .log files in c:\temp path
  • older than 14 days
  • and delete them

Here is small explanation of the command line:

  • -p “full path” is used to specify exact path to the destination dir, it can be c:\ or c:\temp
  • -s says to forfiles that it will go recursive into subdirs
  • -m *.ext creates filter for files of the .ext extension, it can be *.* as well
  • -d 7 says to forfiles to filter files from output above to match current date minus number of days
  • -c “command” executes command on files that are returned from output of forfiles command
  • cmd /c command is saying to cmd that is command prompt to execute command and terminate itself

Now to test this batch file you can delete or comment out command part so you will get output from forfiles only without deleting of the files. Also you can use move command instead of del to move logfiles to another location.

If everything works like it should open Start->Control panel->Scheduled tasks and create new task to executes every day or in any time frame that you want.

Unable to delete file or folder?

Thursday, August 21st, 2008

If you have ever tried to delete bunch of files at once you would in almost 50% cases get following error:

This can be really annoying when you work on servers.

Luckily instead of search-and-destroy-process action there is one FREE program that can unlock file for you and delete it or delete it after reboot.

Program is called Unlocker and it was written by Cedrick Collomb, it’s free and you can download it on this page.