#178563 - 2007-07-31 02:15 PM
Bulk rename files
|
green78
Fresh Scripter
Registered: 2007-05-02
Posts: 34
|
Hi folks,
I'm trying to do the following. I have the following filenames in my folder:
BX0_FF3_AC1.SPL BX1_FF43_AC2.SPL BX3_FFFJ1_AC88.SPL -------------------- etc.
What I want to do is simply rename all files that have string "_AC" inside to:
BG_STAT_$ORIGINALFILENAME, i.e.
files that I want to have in the folder should be:
BG_STAT_BX0_FF3_AC1.SPL BG_STAT_BX1_FF43_AC2.SPL BG_STAT_BX3_FFFJ1_AC88.SPL
When I try something like this:
SHELL "cmd /c ren *_AC* BG_STAT_*AC*" I get the first 8 symbols of the original filename replaced by "BG_STAT" .... and this drives me mad
|
|
Top
|
|
|
|
#178567 - 2007-07-31 02:45 PM
Re: Bulk rename files
[Re: green78]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
I think you may be out of luck. This was acknowledged as a problem some time ago, and I can't find any update to say that is has been fixed: http://support.microsoft.com/kb/96955
|
|
Top
|
|
|
|
#178574 - 2007-07-31 03:46 PM
Re: Bulk rename files
[Re: Richard H.]
|
green78
Fresh Scripter
Registered: 2007-05-02
Posts: 34
|
Thanks Richard.....
Bloody hell, do you think this can be avoided by Kix ? I tried even the COPY command in Kix, tried to cheat.... but still the same:
Dim $bgstat
$bgstat = "BG_STAT_"
COPY "T:\Exr\*_AC*" $bgstat + "*_AC*"
Same, same result.....
I will try suggested above, hope there is some way out of it...
|
|
Top
|
|
|
|
#178576 - 2007-07-31 04:10 PM
Re: Bulk rename files
[Re: Witto]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Can this help you?
;************************************************************************* ; Script Name: Find-_AC-Files ; Author: green78 ; Date: 31/07/2007 ; Description: Find and rename files with _AC in directory ;*************************************************************************
;Script Options If Not @LOGONMODE Break On Else Break Off EndIf Dim $RC $RC = SetOption("Explicit", "On") $RC = SetOption("NoMacrosInStrings", "On") $RC = SetOption("NoVarsInStrings", "On") If @SCRIPTEXE = "KIX32.EXE" $RC = SetOption("WrapAtEOL", "On") EndIf
;Declare variables Dim $arrFiles, $strFile Dim $strPath Dim $strPrefix, $intPrefixLength
;Initialize variables $strPath = "C:\Test\Test\" $strPrefix = "BG_STAT_" $intPrefixLength = Len($strPrefix)
;Code $arrFiles = DirPlus($strPath,"/M _AC") For Each $strFile in $arrFiles ;$strFile.Name ? ;$strFile.Path ? ;$strFile.ParentFolder ? If Not Left($strFile.Name,$intPrefixLength) = $strPrefix $strFile.Move($strFile.ParentFolder + "\" + $strPrefix + $strFile.Name) EndIf Next
;UDF Section ;Copy the DirPlus UDF here |
|
|
Top
|
|
|
|
#178590 - 2007-07-31 10:47 PM
Re: Bulk rename files
[Re: Les]
|
green78
Fresh Scripter
Registered: 2007-05-02
Posts: 34
|
Witto/Allen,
Really can't be more grateful to you. Works like a dream !
|
|
Top
|
|
|
|
#178591 - 2007-07-31 11:27 PM
Re: Bulk rename files
[Re: green78]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
You're welcome. You could consider if you need to recurs subdirectories (/S) or if you want to avoid renaming directories (/A-D)
$arrFiles = DirPlus($strPath,"/S /A-D /M _AC")
|
|
Top
|
|
|
|
#178592 - 2007-07-31 11:37 PM
Re: Bulk rename files
[Re: Witto]
|
green78
Fresh Scripter
Registered: 2007-05-02
Posts: 34
|
Yep, I checked the UDF - I hope my case doesn't get more complicated. The naming conventions already caused me a lot of headache.....
I only hope one day I will be able to contribute somehow...
Thanks again.
|
|
Top
|
|
|
|
#178593 - 2007-08-01 09:23 AM
Re: Bulk rename files
[Re: green78]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
The naming of my var $strFile in my code is wrong, because it is about an object, not about a string. Maybe you better change it to $objFile
;*************************************************************************
; Script Name: Find-_AC-Files
; Author: green78
; Date: 31/07/2007
; Description: Find and rename files with _AC in directory
;*************************************************************************
;Script Options
If Not @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $RC
$RC = SetOption("Explicit", "On")
$RC = SetOption("NoMacrosInStrings", "On")
$RC = SetOption("NoVarsInStrings", "On")
If @SCRIPTEXE = "KIX32.EXE"
$RC = SetOption("WrapAtEOL", "On")
EndIf
;Declare variables
Dim $arrFiles, $objFile
Dim $strPath, $strPrefix
;Initialize variables
$strPath = "C:\Test\Test\"
$strPrefix = "BG_STAT_"
;Code
;Only list hits that have _AC in their name (/M _AC)
;recurs subdirectories (/s)
;list only files (/A-D)
$arrFiles = DirPlus($strPath,"/S /A-D /M _AC")
For Each $objFile in $arrFiles
;$objFile.Name ?
;$objFile.Path ?
;$objFile.ParentFolder ?
;Only rename files that have not been renamed yet
If Not Left($objFile.Name,Len($strPrefix)) = $strPrefix
$objFile.Move($objFile.ParentFolder + "\" + $strPrefix + $objFile.Name)
EndIf
Next
;UDF Section
;Copy the DirPlus UDF here
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|