Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Swap first and last part of a filename : how ?

Reply
 
Old 01-21-2009   #1 (permalink)
MoiMeme


 
 

Swap first and last part of a filename : how ?

Hi,

I would like to rename a bunch of 250 files by swapping firts and last part
of the filename

files are now named in a work - composer scheme
i need them to be named according to composer - work scheme

All are in same folder

Any way to achieve this programaticaly ( or with an utility ???)


TIA !!!!!!!!!



My System SpecsSystem Spec
Old 01-21-2009   #2 (permalink)
James Whitlow


 
 

Re: Swap first and last part of a filename : how ?

"MoiMeme" <antispam@xxxxxx> wrote in message
news:ujV1rT7eJHA.5408@xxxxxx
Quote:

> Hi,
>
> I would like to rename a bunch of 250 files by swapping firts and last
> part of the filename
>
> files are now named in a work - composer scheme
> i need them to be named according to composer - work scheme
>
> All are in same folder
>
> Any way to achieve this programaticaly ( or with an utility ???)
Can you post a few examples of the filenames, please? Seeing a few
filename examples will help determine if there are any character(s) that can
use as a reliable delimiter.


My System SpecsSystem Spec
Old 01-21-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Swap first and last part of a filename : how ?


"MoiMeme" <antispam@xxxxxx> wrote in message
news:ujV1rT7eJHA.5408@xxxxxx
Quote:

> Hi,
>
> I would like to rename a bunch of 250 files by swapping firts and last
> part of the filename
>
> files are now named in a work - composer scheme
> i need them to be named according to composer - work scheme
>
> All are in same folder
>
> Any way to achieve this programaticaly ( or with an utility ???)
>
>
> TIA !!!!!!!!!
You can use the FileSystemObject to enumerate the files, parse the names,
and rename. For example, if the file names are similar to:

First Last.txt

then someting similar to below should work:
=========
Option Explicit

Dim objFSO, objFolder, colFiles, objFile
Dim strName, strBase, strExtension, arrNames
Dim intIndex, blnChanged

Set objFSO = CreateObject("Scripting.FileSystemObject")

' Enumrate all files in specified folder.
Set objFolder = objFSO.GetFolder("c:\rlm\Scripts\RenameFiles")
Set colFiles = objFolder.Files
For Each objFile In colFiles
' Retrieve file name.
strName = objFile.Name
' Keep track if file is to be renamed.
blnChanged = False
' Find "." in name.
intIndex = InStr(strName, ".")
If (intIndex > 0) Then
' Parse base name and extension.
strBase = Left(strName, intIndex - 1)
strExtension = Mid(strName, intIndex + 1)
Else
strBase = strName
strExtension = ""
End If
' Parse base name for two names delimited by a space.
arrNames = Split(strBase, " ")
' If there are two names, reverse them.
If (UBound(arrNames) = 1) Then
strBase = arrNames(1) & " " & arrNames(0)
blnChanged = True
End If
' If names reversed, rename the file
If (blnChanged = True) Then
strName = strBase & "." & strExtension
objFile.Name = strName
End If
Next

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 01-21-2009   #4 (permalink)
MoiMeme


 
 

Re: Swap first and last part of a filename : how ?

Filenames are in following format : "work - composer". Allways a space then
'-' then again a space

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> a écrit dans
le message de news: e1Vkyb%23eJHA.5956@xxxxxx
Quote:

>
> "MoiMeme" <antispam@xxxxxx> wrote in message
> news:ujV1rT7eJHA.5408@xxxxxx
Quote:

>> Hi,
>>
>> I would like to rename a bunch of 250 files by swapping firts and last
>> part of the filename
>>
>> files are now named in a work - composer scheme
>> i need them to be named according to composer - work scheme
>>
>> All are in same folder
>>
>> Any way to achieve this programaticaly ( or with an utility ???)
>>
>>
>> TIA !!!!!!!!!
>
> You can use the FileSystemObject to enumerate the files, parse the names,
> and rename. For example, if the file names are similar to:
>
> First Last.txt
>
> then someting similar to below should work:
> =========
> Option Explicit
>
> Dim objFSO, objFolder, colFiles, objFile
> Dim strName, strBase, strExtension, arrNames
> Dim intIndex, blnChanged
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> ' Enumrate all files in specified folder.
> Set objFolder = objFSO.GetFolder("c:\rlm\Scripts\RenameFiles")
> Set colFiles = objFolder.Files
> For Each objFile In colFiles
> ' Retrieve file name.
> strName = objFile.Name
> ' Keep track if file is to be renamed.
> blnChanged = False
> ' Find "." in name.
> intIndex = InStr(strName, ".")
> If (intIndex > 0) Then
> ' Parse base name and extension.
> strBase = Left(strName, intIndex - 1)
> strExtension = Mid(strName, intIndex + 1)
> Else
> strBase = strName
> strExtension = ""
> End If
> ' Parse base name for two names delimited by a space.
> arrNames = Split(strBase, " ")
> ' If there are two names, reverse them.
> If (UBound(arrNames) = 1) Then
> strBase = arrNames(1) & " " & arrNames(0)
> blnChanged = True
> End If
> ' If names reversed, rename the file
> If (blnChanged = True) Then
> strName = strBase & "." & strExtension
> objFile.Name = strName
> End If
> Next
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>

My System SpecsSystem Spec
Old 01-21-2009   #5 (permalink)
Richard Mueller [MVP]


 
 

Re: Swap first and last part of a filename : how ?

Then replace this part of the code I posted:
==========
' Parse base name for two names delimited by a space.
arrNames = Split(strBase, " ")
' If there are two names, reverse them.
If (UBound(arrNames) = 1) Then
strBase = arrNames(1) & " " & arrNames(0)
blnChanged = True
End If
==========
with this:
==========
' Parse base name for two names delimited by " - ".
arrNames = Split(strBase, " - ")
' If there are two names, reverse them.
If (UBound(arrNames) = 1) Then
strBase = arrNames(1) & " - " & arrNames(0)
blnChanged = True
End If
==========

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"MoiMeme" <antispam@xxxxxx> wrote in message
news:eWLa3w%23eJHA.1172@xxxxxx
Quote:

> Filenames are in following format : "work - composer". Allways a space
> then '-' then again a space
>
> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> a écrit
> dans le message de news: e1Vkyb%23eJHA.5956@xxxxxx
Quote:

>>
>> "MoiMeme" <antispam@xxxxxx> wrote in message
>> news:ujV1rT7eJHA.5408@xxxxxx
Quote:

>>> Hi,
>>>
>>> I would like to rename a bunch of 250 files by swapping firts and last
>>> part of the filename
>>>
>>> files are now named in a work - composer scheme
>>> i need them to be named according to composer - work scheme
>>>
>>> All are in same folder
>>>
>>> Any way to achieve this programaticaly ( or with an utility ???)
>>>
>>>
>>> TIA !!!!!!!!!
>>
>> You can use the FileSystemObject to enumerate the files, parse the names,
>> and rename. For example, if the file names are similar to:
>>
>> First Last.txt
>>
>> then someting similar to below should work:
>> =========
>> Option Explicit
>>
>> Dim objFSO, objFolder, colFiles, objFile
>> Dim strName, strBase, strExtension, arrNames
>> Dim intIndex, blnChanged
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>
>> ' Enumrate all files in specified folder.
>> Set objFolder = objFSO.GetFolder("c:\rlm\Scripts\RenameFiles")
>> Set colFiles = objFolder.Files
>> For Each objFile In colFiles
>> ' Retrieve file name.
>> strName = objFile.Name
>> ' Keep track if file is to be renamed.
>> blnChanged = False
>> ' Find "." in name.
>> intIndex = InStr(strName, ".")
>> If (intIndex > 0) Then
>> ' Parse base name and extension.
>> strBase = Left(strName, intIndex - 1)
>> strExtension = Mid(strName, intIndex + 1)
>> Else
>> strBase = strName
>> strExtension = ""
>> End If
>> ' Parse base name for two names delimited by a space.
>> arrNames = Split(strBase, " ")
>> ' If there are two names, reverse them.
>> If (UBound(arrNames) = 1) Then
>> strBase = arrNames(1) & " " & arrNames(0)
>> blnChanged = True
>> End If
>> ' If names reversed, rename the file
>> If (blnChanged = True) Then
>> strName = strBase & "." & strExtension
>> objFile.Name = strName
>> End If
>> Next
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>
>

My System SpecsSystem Spec
Old 01-21-2009   #6 (permalink)
MoiMeme


 
 

Re: Swap first and last part of a filename : how ?

Thanks !

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> a écrit dans
le message de news: eGJr33%23eJHA.3456@xxxxxx
Quote:

> Then replace this part of the code I posted:
> ==========
> ' Parse base name for two names delimited by a space.
> arrNames = Split(strBase, " ")
> ' If there are two names, reverse them.
> If (UBound(arrNames) = 1) Then
> strBase = arrNames(1) & " " & arrNames(0)
> blnChanged = True
> End If
> ==========
> with this:
> ==========
> ' Parse base name for two names delimited by " - ".
> arrNames = Split(strBase, " - ")
> ' If there are two names, reverse them.
> If (UBound(arrNames) = 1) Then
> strBase = arrNames(1) & " - " & arrNames(0)
> blnChanged = True
> End If
> ==========
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "MoiMeme" <antispam@xxxxxx> wrote in message
> news:eWLa3w%23eJHA.1172@xxxxxx
Quote:

>> Filenames are in following format : "work - composer". Allways a space
>> then '-' then again a space
>>
>> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> a écrit
>> dans le message de news: e1Vkyb%23eJHA.5956@xxxxxx
Quote:

>>>
>>> "MoiMeme" <antispam@xxxxxx> wrote in message
>>> news:ujV1rT7eJHA.5408@xxxxxx
>>>> Hi,
>>>>
>>>> I would like to rename a bunch of 250 files by swapping firts and last
>>>> part of the filename
>>>>
>>>> files are now named in a work - composer scheme
>>>> i need them to be named according to composer - work scheme
>>>>
>>>> All are in same folder
>>>>
>>>> Any way to achieve this programaticaly ( or with an utility ???)
>>>>
>>>>
>>>> TIA !!!!!!!!!
>>>
>>> You can use the FileSystemObject to enumerate the files, parse the
>>> names, and rename. For example, if the file names are similar to:
>>>
>>> First Last.txt
>>>
>>> then someting similar to below should work:
>>> =========
>>> Option Explicit
>>>
>>> Dim objFSO, objFolder, colFiles, objFile
>>> Dim strName, strBase, strExtension, arrNames
>>> Dim intIndex, blnChanged
>>>
>>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>>
>>> ' Enumrate all files in specified folder.
>>> Set objFolder = objFSO.GetFolder("c:\rlm\Scripts\RenameFiles")
>>> Set colFiles = objFolder.Files
>>> For Each objFile In colFiles
>>> ' Retrieve file name.
>>> strName = objFile.Name
>>> ' Keep track if file is to be renamed.
>>> blnChanged = False
>>> ' Find "." in name.
>>> intIndex = InStr(strName, ".")
>>> If (intIndex > 0) Then
>>> ' Parse base name and extension.
>>> strBase = Left(strName, intIndex - 1)
>>> strExtension = Mid(strName, intIndex + 1)
>>> Else
>>> strBase = strName
>>> strExtension = ""
>>> End If
>>> ' Parse base name for two names delimited by a space.
>>> arrNames = Split(strBase, " ")
>>> ' If there are two names, reverse them.
>>> If (UBound(arrNames) = 1) Then
>>> strBase = arrNames(1) & " " & arrNames(0)
>>> blnChanged = True
>>> End If
>>> ' If names reversed, rename the file
>>> If (blnChanged = True) Then
>>> strName = strBase & "." & strExtension
>>> objFile.Name = strName
>>> End If
>>> Next
>>>
>>> --
>>> Richard Mueller
>>> MVP Directory Services
>>> Hilltop Lab - http://www.rlmueller.net
>>> --
>>>
>>>
>>
>>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Using swap file or not for VM Virtual PC
motherboard swap Vista General
Tip: swap from x32 to x64 WMP Vista music pictures video
Swap 2 hardisks Vista installation & setup
SATA Hot swap Vista hardware & devices


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46