![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 ???) filename examples will help determine if there are any character(s) that can use as a reliable delimiter. |
My System Specs![]() |
| | #3 (permalink) |
| | 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 !!!!!!!!! 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||