+ Reply to Thread
Results 1 to 9 of 9

rename files in a folder

  1. #1
    Varun Nair
    Guest

    rename files in a folder

    Hi,

    I have a set of .wav files in a folder. Can some one help me with a macro
    which could rename all the files in a folder.

    the naming scheme should be as mentioned below

    oldname : 123456_xyz
    newname: 123456

    i.e. the new name should only contain the first 6 first characters of the
    ond name.

    --
    Varun Nair


  2. #2
    Bob Phillips
    Guest

    Re: rename files in a folder

    Dim FSO As Object

    Sub ProcessFiles()
    Dim i As Long
    Dim sFolder As String
    Dim fldr As Object
    Dim Folder As Object
    Dim file As Object
    Dim Files As Object
    Dim this As Workbook
    Dim cnt As Long
    Dim sName As String

    Set FSO = CreateObject("Scripting.FileSystemObject")

    Set this = ActiveWorkbook
    sFolder = "C:\MyTest"
    If sFolder <> "" Then
    Set Folder = FSO.GetFolder(sFolder)

    Set Files = Folder.Files
    cnt = 1
    For Each file In Files
    If file.Type = "Microsoft Excel Worksheet" Then
    sName = Replace(file.Name, ".xls", "")
    ' Name file.Path As Replace(file.Path, sname, Left(sname, 6))
    cnt = cnt + 1
    End If
    Next file

    End If ' sFolder <> ""

    End Sub



    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Varun Nair" <VarunNair@discussions.microsoft.com> wrote in message
    news:EE60660E-8967-45F0-9D04-E6F9F3E06539@microsoft.com...
    > Hi,
    >
    > I have a set of .wav files in a folder. Can some one help me with a macro
    > which could rename all the files in a folder.
    >
    > the naming scheme should be as mentioned below
    >
    > oldname : 123456_xyz
    > newname: 123456
    >
    > i.e. the new name should only contain the first 6 first characters of the
    > ond name.
    >
    > --
    > Varun Nair
    >




  3. #3
    Varun Nair
    Guest

    Re: rename files in a folder

    Hi Bob,

    But as i have mentioned that I have .wav files in my folder and not excel
    files.
    would this code work for wav files as well?
    --
    Varun Nair



    "Bob Phillips" wrote:

    > Dim FSO As Object
    >
    > Sub ProcessFiles()
    > Dim i As Long
    > Dim sFolder As String
    > Dim fldr As Object
    > Dim Folder As Object
    > Dim file As Object
    > Dim Files As Object
    > Dim this As Workbook
    > Dim cnt As Long
    > Dim sName As String
    >
    > Set FSO = CreateObject("Scripting.FileSystemObject")
    >
    > Set this = ActiveWorkbook
    > sFolder = "C:\MyTest"
    > If sFolder <> "" Then
    > Set Folder = FSO.GetFolder(sFolder)
    >
    > Set Files = Folder.Files
    > cnt = 1
    > For Each file In Files
    > If file.Type = "Microsoft Excel Worksheet" Then
    > sName = Replace(file.Name, ".xls", "")
    > ' Name file.Path As Replace(file.Path, sname, Left(sname, 6))
    > cnt = cnt + 1
    > End If
    > Next file
    >
    > End If ' sFolder <> ""
    >
    > End Sub
    >
    >
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (replace somewhere in email address with gmail if mailing direct)
    >
    > "Varun Nair" <VarunNair@discussions.microsoft.com> wrote in message
    > news:EE60660E-8967-45F0-9D04-E6F9F3E06539@microsoft.com...
    > > Hi,
    > >
    > > I have a set of .wav files in a folder. Can some one help me with a macro
    > > which could rename all the files in a folder.
    > >
    > > the naming scheme should be as mentioned below
    > >
    > > oldname : 123456_xyz
    > > newname: 123456
    > >
    > > i.e. the new name should only contain the first 6 first characters of the
    > > ond name.
    > >
    > > --
    > > Varun Nair
    > >

    >
    >
    >


  4. #4
    Norman Jones
    Guest

    Re: rename files in a folder

    Hi Varun,

    As an alternative, try:

    '=============>>
    Public Sub Tester001()
    Dim FName As String
    Dim MyPath As String
    Dim OldName As String
    Dim NewName As String

    MyPath = "C:\B\Test\" '<<==== CHANGE
    FName = Dir(MyPath & "*.Wav")
    Do While FName <> ""
    OldName = FName
    NewName = Left(OldName, 6) & ".Wav"

    Name MyPath & OldName As MyPath & NewName

    FName = Dir()
    Loop
    End Sub
    '<<=============



    ---
    Regards,
    Norman



    "Varun Nair" <VarunNair@discussions.microsoft.com> wrote in message
    news:EE60660E-8967-45F0-9D04-E6F9F3E06539@microsoft.com...
    > Hi,
    >
    > I have a set of .wav files in a folder. Can some one help me with a macro
    > which could rename all the files in a folder.
    >
    > the naming scheme should be as mentioned below
    >
    > oldname : 123456_xyz
    > newname: 123456
    >
    > i.e. the new name should only contain the first 6 first characters of the
    > ond name.
    >
    > --
    > Varun Nair
    >




  5. #5
    Varun Nair
    Guest

    Re: rename files in a folder

    HI norman,

    I tried using your code.
    but it didn't do anything.

    a reminder that i am using the VB on excel. is there any .ocx that i need to
    include?
    --
    Varun Nair



    "Norman Jones" wrote:

    > Hi Varun,
    >
    > As an alternative, try:
    >
    > '=============>>
    > Public Sub Tester001()
    > Dim FName As String
    > Dim MyPath As String
    > Dim OldName As String
    > Dim NewName As String
    >
    > MyPath = "C:\B\Test\" '<<==== CHANGE
    > FName = Dir(MyPath & "*.Wav")
    > Do While FName <> ""
    > OldName = FName
    > NewName = Left(OldName, 6) & ".Wav"
    >
    > Name MyPath & OldName As MyPath & NewName
    >
    > FName = Dir()
    > Loop
    > End Sub
    > '<<=============
    >
    >
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "Varun Nair" <VarunNair@discussions.microsoft.com> wrote in message
    > news:EE60660E-8967-45F0-9D04-E6F9F3E06539@microsoft.com...
    > > Hi,
    > >
    > > I have a set of .wav files in a folder. Can some one help me with a macro
    > > which could rename all the files in a folder.
    > >
    > > the naming scheme should be as mentioned below
    > >
    > > oldname : 123456_xyz
    > > newname: 123456
    > >
    > > i.e. the new name should only contain the first 6 first characters of the
    > > ond name.
    > >
    > > --
    > > Varun Nair
    > >

    >
    >
    >


  6. #6
    Varun Nair
    Guest

    Re: rename files in a folder

    HI norman,

    I tried using your code.
    but it didn't do anything.

    a reminder that i am using the VB on excel. is there any .ocx that i need to
    include?
    --
    Varun Nair



    "Norman Jones" wrote:

    > Hi Varun,
    >
    > As an alternative, try:
    >
    > '=============>>
    > Public Sub Tester001()
    > Dim FName As String
    > Dim MyPath As String
    > Dim OldName As String
    > Dim NewName As String
    >
    > MyPath = "C:\B\Test\" '<<==== CHANGE
    > FName = Dir(MyPath & "*.Wav")
    > Do While FName <> ""
    > OldName = FName
    > NewName = Left(OldName, 6) & ".Wav"
    >
    > Name MyPath & OldName As MyPath & NewName
    >
    > FName = Dir()
    > Loop
    > End Sub
    > '<<=============
    >
    >
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "Varun Nair" <VarunNair@discussions.microsoft.com> wrote in message
    > news:EE60660E-8967-45F0-9D04-E6F9F3E06539@microsoft.com...
    > > Hi,
    > >
    > > I have a set of .wav files in a folder. Can some one help me with a macro
    > > which could rename all the files in a folder.
    > >
    > > the naming scheme should be as mentioned below
    > >
    > > oldname : 123456_xyz
    > > newname: 123456
    > >
    > > i.e. the new name should only contain the first 6 first characters of the
    > > ond name.
    > >
    > > --
    > > Varun Nair
    > >

    >
    >
    >


  7. #7
    Bob Phillips
    Guest

    Re: rename files in a folder

    Yes, of course it would, it is just a name

    Change

    If file.Type = "Microsoft Excel Worksheet" Then

    to

    If file.Type = "WAV File" Then


    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "Varun Nair" <VarunNair@discussions.microsoft.com> wrote in message
    news:65DE862E-6DAF-43F8-AD4D-35027913D246@microsoft.com...
    > Hi Bob,
    >
    > But as i have mentioned that I have .wav files in my folder and not excel
    > files.
    > would this code work for wav files as well?
    > --
    > Varun Nair
    >
    >
    >
    > "Bob Phillips" wrote:
    >
    > > Dim FSO As Object
    > >
    > > Sub ProcessFiles()
    > > Dim i As Long
    > > Dim sFolder As String
    > > Dim fldr As Object
    > > Dim Folder As Object
    > > Dim file As Object
    > > Dim Files As Object
    > > Dim this As Workbook
    > > Dim cnt As Long
    > > Dim sName As String
    > >
    > > Set FSO = CreateObject("Scripting.FileSystemObject")
    > >
    > > Set this = ActiveWorkbook
    > > sFolder = "C:\MyTest"
    > > If sFolder <> "" Then
    > > Set Folder = FSO.GetFolder(sFolder)
    > >
    > > Set Files = Folder.Files
    > > cnt = 1
    > > For Each file In Files
    > > If file.Type = "Microsoft Excel Worksheet" Then
    > > sName = Replace(file.Name, ".xls", "")
    > > ' Name file.Path As Replace(file.Path, sname, Left(sname,

    6))
    > > cnt = cnt + 1
    > > End If
    > > Next file
    > >
    > > End If ' sFolder <> ""
    > >
    > > End Sub
    > >
    > >
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (replace somewhere in email address with gmail if mailing direct)
    > >
    > > "Varun Nair" <VarunNair@discussions.microsoft.com> wrote in message
    > > news:EE60660E-8967-45F0-9D04-E6F9F3E06539@microsoft.com...
    > > > Hi,
    > > >
    > > > I have a set of .wav files in a folder. Can some one help me with a

    macro
    > > > which could rename all the files in a folder.
    > > >
    > > > the naming scheme should be as mentioned below
    > > >
    > > > oldname : 123456_xyz
    > > > newname: 123456
    > > >
    > > > i.e. the new name should only contain the first 6 first characters of

    the
    > > > ond name.
    > > >
    > > > --
    > > > Varun Nair
    > > >

    > >
    > >
    > >




  8. #8
    Varun Nair
    Guest

    Re: rename files in a folder

    hi bob,

    this code is not working on my excel !
    --
    Varun Nair



    "Bob Phillips" wrote:

    > Dim FSO As Object
    >
    > Sub ProcessFiles()
    > Dim i As Long
    > Dim sFolder As String
    > Dim fldr As Object
    > Dim Folder As Object
    > Dim file As Object
    > Dim Files As Object
    > Dim this As Workbook
    > Dim cnt As Long
    > Dim sName As String
    >
    > Set FSO = CreateObject("Scripting.FileSystemObject")
    >
    > Set this = ActiveWorkbook
    > sFolder = "C:\MyTest"
    > If sFolder <> "" Then
    > Set Folder = FSO.GetFolder(sFolder)
    >
    > Set Files = Folder.Files
    > cnt = 1
    > For Each file In Files
    > If file.Type = "Microsoft Excel Worksheet" Then
    > sName = Replace(file.Name, ".xls", "")
    > ' Name file.Path As Replace(file.Path, sname, Left(sname, 6))
    > cnt = cnt + 1
    > End If
    > Next file
    >
    > End If ' sFolder <> ""
    >
    > End Sub
    >
    >
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (replace somewhere in email address with gmail if mailing direct)
    >
    > "Varun Nair" <VarunNair@discussions.microsoft.com> wrote in message
    > news:EE60660E-8967-45F0-9D04-E6F9F3E06539@microsoft.com...
    > > Hi,
    > >
    > > I have a set of .wav files in a folder. Can some one help me with a macro
    > > which could rename all the files in a folder.
    > >
    > > the naming scheme should be as mentioned below
    > >
    > > oldname : 123456_xyz
    > > newname: 123456
    > >
    > > i.e. the new name should only contain the first 6 first characters of the
    > > ond name.
    > >
    > > --
    > > Varun Nair
    > >

    >
    >
    >


  9. #9
    Norman Jones
    Guest

    Re: rename files in a folder

    Hi Varun,

    The suggested code works for me without problem.

    I assumed that your wav files had a .Wav extension. If the the extension is
    different (or non-existant), then you will need accordingly to replace the
    expression: & "*.Wav" in the line

    >> FName = Dir(MyPath & "*.Wav")



    ---
    Regards,
    Norman



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1