Page 1 of 1 1
Topic Options
#178563 - 2007-07-31 02:15 PM Bulk rename files
green78 Offline
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
#178565 - 2007-07-31 02:30 PM Re: Bulk rename files [Re: green78]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Serves you right for using DOS commands instead of KiX. Did you try using KiX?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#178566 - 2007-07-31 02:31 PM Re: Bulk rename files [Re: green78]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Look at DirPlus() UDF, and INSTR() Function, using both of these you should be able to do what you need.

http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=82153

http://www.kixtart.org/manual/Functions/Instr.htm
_________________________
Today is the tomorrow you worried about yesterday.

Top
#178567 - 2007-07-31 02:45 PM Re: Bulk rename files [Re: green78]
Richard H. Administrator Offline
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 Offline
Fresh Scripter

Registered: 2007-05-02
Posts: 34
 Originally Posted By: Richard H.
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


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:

 Code:
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
#178575 - 2007-07-31 03:55 PM Re: Bulk rename files [Re: Gargoyle]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I think it is possible to include the InStr() somewhere in the DirPlus() arguments
Top
#178576 - 2007-07-31 04:10 PM Re: Bulk rename files [Re: Witto]
Witto Offline
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
#178579 - 2007-07-31 06:23 PM Re: Bulk rename files [Re: Witto]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Taking Witto example a little further... Remove the semicolon on the move command when you are sure it will do what you want.

$strPath = "C:\Test\Test\"
$arrFiles = DirPlus($strPath,"/M _AC")
For Each $strFile in $arrFiles
? "Original File: " + $strFile.Name " - "
$renamed= "BG_STAT_" + $strFile.name
;move $strpath + $strFile.Name $strpath + $renamed
if exist($strPath + $renamed)
"Renamed: " +$renamed
else
"Error"
endif
Next
_________________________
(... better days ahead)

Top
#178580 - 2007-07-31 06:33 PM Re: Bulk rename files [Re: Allen]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Since DirPlus() returns the FSO COM handle, you should be able to use the FSO method to rename.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#178581 - 2007-07-31 06:45 PM Re: Bulk rename files [Re: Les]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Updated my code and made it work with the FSO
Top
#178582 - 2007-07-31 07:54 PM Re: Bulk rename files [Re: Witto]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Nice
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#178585 - 2007-07-31 08:18 PM Re: Bulk rename files [Re: green78]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
FREE util - donations excepted

Bulk Rename Utility
http://www.bulkrenameutility.co.uk/

Bulk Rename Utility, Build 2.6.0.1
http://www.bulkrenameutility.co.uk/Download.php

Top
#178590 - 2007-07-31 10:47 PM Re: Bulk rename files [Re: Les]
green78 Offline
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 Offline
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)
 Code:
$arrFiles = DirPlus($strPath,"/S /A-D /M _AC")

Top
#178592 - 2007-07-31 11:37 PM Re: Bulk rename files [Re: Witto]
green78 Offline
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 Offline
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
 Code:
;*************************************************************************
; 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
#178600 - 2007-08-01 02:42 PM Re: Bulk rename files [Re: Witto]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Damn those Hungarians. ;\)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.084 seconds in which 0.038 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org