#141041 - 2005-06-06 03:56 PM
Listing folders...
|
chrisobo
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
|
|
|
|
#141045 - 2005-06-07 10:58 AM
Re: Listing folders...
|
chrisobo
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
   
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
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
|
|
|
|
#141050 - 2005-06-07 04:40 PM
Re: Listing folders...
|
chrisobo
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
|
|
|
|
#141053 - 2005-06-07 04:47 PM
Re: Listing folders...
|
chrisobo
Fresh Scripter
Registered: 2005-05-06
Posts: 9
|
An upgrade sorted the issue. Thanks for all your help everyone
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1046 anonymous users online.
|
|
|