Page 1 of 1 1
Topic Options
#141041 - 2005-06-06 03:56 PM Listing folders...
chrisobo Offline
Fresh Scripter

Registered: 2005-05-06
Posts: 9
hi all,
I'm trying to add a prefix to all of the subfolders in a directory. eg rename c:\parentfolder\folder1 to c:\parentfolder\MY_folder1 and so on...

Does anybody have any ideas how I can do this please?
Many thanks in advance

Top
#141042 - 2005-06-06 04:07 PM Re: Listing folders...
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Yup.

Look in the manual for the DIR() function to enumerate the contents, the GetFileAttr() function to check if the entry is a folder and the Move command to rename it.

Top
#141043 - 2005-06-06 04:08 PM Re: Listing folders...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Have you taken a look at the MOVE command?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#141044 - 2005-06-06 04:22 PM Re: Listing folders...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you need to include subdirs, there is the full-featured DirPlus() UDF that Bryce wrote, otherwise you could use my lean DDir() UDF to enum dirs one level deep.
Code:

Function DDir($Start)
;Does not support WildCards and FileSpec must end with \
Dim $TmpArray[0], $Dir, $Index, $
$Dir = Dir($Start)
While @Error = 0
If $Dir <> '.' And $Dir <> '..' And GetFileAttr($Start + $Dir) & 16
$TmpArray[$Index] = $Dir
$Index = $Index + 1
ReDim Preserve $TmpArray[$Index]
EndIf
$Dir = Dir()
Loop
If Ubound($TmpArray)
ReDim Preserve $TmpArray[Ubound($TmpArray)-1]
EndIf
$DDir = $TmpArray
EndFunction



Either one returns an array and using a FOR loop, you can iterate through them.
Code:

For Each $Folder in DDir('C:\ParentFolder\')
;do stuff
Next

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#141045 - 2005-06-07 10:58 AM Re: Listing folders...
chrisobo Offline
Fresh Scripter

Registered: 2005-05-06
Posts: 9
Can you use the MOVE command with variables.
ie: move "c:\temp\"+$filename1 "c:\temp\"+$filename2

Top
#141046 - 2005-06-07 11:14 AM Re: Listing folders...
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Can you use the MOVE command with variables.



Yes.

Here is a working rename script - I've commented out the "MOVE" to avoid accidents, remove the ";" when you are happy with what it is doing:
Code:
Break ON
Dim $sParent,$sEntry,$sPrefix,$sNewEntry

$sParent="C:\TEMP"
$sPrefix="MY_"

$sEntry=Dir($sParent)
While Not @ERROR
If $sEntry<>"." AND $sEntry<>".." AND $sEntry<>"" AND (16 & GetFileAttr($sParent+"\"+$sEntry))
$sNewEntry=$sPrefix+$sEntry
"Renaming "+$sEntry+" -> "+$sNewEntry+": "
If Not Exist($sParent+"\"+$sNewEntry)
;Move $sParent+"\"+$sEntry $sParent+"\"+$sNewEntry
If @ERROR " **FAILED with "+@ERROR+"**"+@CRLF Else "OK"+@CRLF EndIf
Else
" **DESTINATION ALREADY EXISTS**"+@CRLF
EndIf
EndIf
$sEntry=Dir("")
Loop

Exit 0


Top
#141047 - 2005-06-07 04:09 PM Re: Listing folders...
chrisobo Offline
Fresh Scripter

Registered: 2005-05-06
Posts: 9
Yep, similar (better) to the code I created. ran it but it still errors out on the MOVE command though...
Top
#141048 - 2005-06-07 04:28 PM Re: Listing folders...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if you don't say what that error is, how one can know what's the problem?
I just quess, you have a fossile kix.
_________________________
!

download KiXnet

Top
#141049 - 2005-06-07 04:38 PM Re: Listing folders...
Les Offline
KiX Master
*****

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

Top
#141050 - 2005-06-07 04:40 PM Re: Listing folders...
chrisobo Offline
Fresh Scripter

Registered: 2005-05-06
Posts: 9
The PC 'beeps' and the screen disappears... If I knew the error I would have included it. Yes, the version we're using is really old... Time for an upgrade I think.
Top
#141051 - 2005-06-07 04:41 PM Re: Listing folders...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja, that's the word.
thanks.
_________________________
!

download KiXnet

Top
#141052 - 2005-06-07 04:45 PM Re: Listing folders...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, if it beeps like that, it displays the error but as you don't have command prompt opened, you miss it.
most likely, it says something like "unknown command/function: MOVE"

that means, yes, your kix is old.
_________________________
!

download KiXnet

Top
#141053 - 2005-06-07 04:47 PM Re: Listing folders...
chrisobo Offline
Fresh Scripter

Registered: 2005-05-06
Posts: 9
An upgrade sorted the issue. Thanks for all your help everyone
Top
#141054 - 2005-06-07 04:49 PM Re: Listing folders...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
See our FAQ section.
_________________________
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 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.698 seconds in which 0.01 seconds were spent on a total of 12 queries. Zlib compression enabled.

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