Re: Rename files with specific file extension

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Curtis Fray (curtis.fray_at_Xbssmail.nhs.uk)
Date: 01/31/05


Date: Mon, 31 Jan 2005 15:08:29 -0000

Hi again,

Sorry there is one addition that would be helpful. If a pst file is open
during the running of this, it errors. How can I update the script so it
continues when it encounters an error?

Thanks,

Curtis.

"Steve Fulton" <cerberus40@hotmail.com> wrote in message
news:opslgwygsmboz00o@msnews.microsoft.com...
> Curtis Fray wrote:
>
>> Could anyone tell me how I can write a script which will scan all files
>> in
>> all folders on a drive and rename anything with a *.pst extension to a
>> *.ps1
>> extension?
>
> Dim Drive, Root, Pst
>
> Drive = "A" 'your drive spec here
>
> Set Root = CreateObject("Scripting.FileSystemObject"). _
> GetDrive(Drive).RootFolder
>
> Set Pst = New RegExp
> With Pst
> .Pattern = "\.pst$"
> .IgnoreCase = True
> .Global = False
> .Multiline = False
> End With
>
> Call Rename(Root, Pst)
>
> Sub Rename(Folder, RegExp)
> Dim SubFolder, File
>
> For Each File in Folder.Files
> If RegExp.Test(File.Name) Then
> File.Name = RegExp.Replace(File.Name, ".ps1")
> End If
> Next
>
> For Each SubFolder In Folder.SubFolders
> Call Rename(SubFolder, RegExp)
> Next
> End Sub
>
>> Curtis.
>
> Please use a proper separator (two dashes and a space "-- ") before
> your signature.
>
> --
> Steve
>
> Those who dream by day are cognizant of many things which escape those
> who dream only by night. -Edgar Allan Poe



Relevant Pages

  • Re: Rename files with specific file extension
    ... Thanks very much for the speedy reply Steve. ... I've updated my signature as per your recommendations. ... > Curtis Fray wrote: ... > Dim Drive, Root, Pst ...
    (microsoft.public.scripting.vbscript)
  • Re: Rename files with specific file extension
    ... Dim Drive, Root, Pst ... Sub Rename(Folder, RegExp) ... Dim SubFolder, File ... Those who dream by day are cognizant of many things which escape those ...
    (microsoft.public.scripting.vbscript)
  • Re: Rename files with specific file extension
    ... >> Dim Drive, Root, Pst ... >> Sub Rename ... >> Dim SubFolder, File ... >> Call Rename(SubFolder, RegExp) ...
    (microsoft.public.scripting.vbscript)