Jump to content

DirMove Need Guide


Go to solution Solved by Spider001,

Recommended Posts

  • Moderators

You could do something like this. As a quick example, given a root folder named Test on the desktop, with the subfolders Test1, Test2, Test3, Test4, Test5...

#include <File.au3>

Local $aArray = _FileListToArray(@DesktopDir & "\Test", "*", $FLTAR_FOLDERS, True)

    For $i = 1 To $aArray[0]
        DirMove($aArray[$i], $aArray[$i] & "_" & $i)
    Next

would produce subfolders Test1_1, Test2_2, Test3_3, Test4_4, Test5_5.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

like i see it you put the number before your drive c:/,....

use a msgbox or ConsoleWrite to what you got on that string

$i & $aArray[$i]

i think you must use _PathSplit

then place your number

and then assemble the whole path again

Edited by Spider001
Link to comment
Share on other sites

  • Moderators

The problem you are going to run into is that when you change the top level folder's name first, you then alter the path for every subsequent folder. Try using the code I supplied to change all the sub folders, then change the parent folder last.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Ok, I get that we have probably have a language barrier here, but you need to clarify what you're trying to do. From your OP, it seems like you have a number of folders that you want to rename, and you're using _FileListToArray to gather a list of the folders to be changed. (Right so far??)

You can't change the top-level folder until last, because that would alter the path for every subsequent folder. So, once you have the array of folders, change all the subfolders first, then change the parent folder last. Something like this:

All the same code I gave you in post #3

#include <File.au3>

Local $aArray = _FileListToArray(@DesktopDir & "\Test", "*", $FLTAR_FOLDERS, True)

    For $i = 1 To $aArray[0]
        DirMove($aArray[$i], $aArray[$i] & "_" & $i)
    Next

Change the parent directory last

;Last Step!

DirMove(@DesktopDir & "\Test", @DesktopDir & "\NewTest", 1)

If it is still not clear, then you need to explain in better detail what you're trying to do.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

OK, I explain better.

I want rename Parent folder and sub folders. mean I have some parent folder that each have many sub folders. Now I want rename parents folder and sub folders.like this:

1 New Folder

   ---1 test

   ---2 test

   ---3 test

2 New Folder

   ---4 test

   ---5 test

   ---6 test

and so on.

Link to comment
Share on other sites

  • Moderators

Please explain what the folders are named before you start, and then what they are named after you run the code I provided to you.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

my folder names before start are like this:

 
Game

   ---Evit

   ---StarWars

   ---IGI

Software

   ---Firefox

   ---Chrome

   ---Babylon

 

now I want add number at first name folders like this:

1 Game

   ---1 Evit

   ---2 StarWars

   ---3 IGI

2 Software

   ---4 Firefox

   ---5 Chrome

   ---6 Babylon

Link to comment
Share on other sites

  • Solution

#include <File.au3>
#include <array.au3>

$tel = 1
$tel1 = 1
Local $aArray = _FileListToArray(@DesktopDir , "*", $FLTAR_FOLDERS, True)
If UBound($aArray) > 0 Then
   For $i = 1 To $aArray[0]
      Local $aArrays = _FileListToArray($aArray[$i] , "*", $FLTAR_FOLDERS, True)
      If UBound($aArrays) > 0 Then
         For $j = 1 To $aArrays[0]
         DirMove($aArrays[$j], _GetPathSplit($aArrays[$j])[1] & _GetPathSplit($aArrays[$j])[2] & $tel1 & _GetPathSplit($aArrays[$j])[3])
         $tel1 += 1
         Next
      EndIf
      DirMove($aArray[$i], _GetPathSplit($aArray[$i])[1] & _GetPathSplit($aArray[$i])[2] & $tel & _GetPathSplit($aArray[$i])[3])
      $tel += 1
   Next
EndIf

Func _GetPathSplit($file)
   Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
   Return _PathSplit($file, $sDrive, $sDir, $sFilename, $sExtension)
EndFunc

Edited by Spider001
Link to comment
Share on other sites

  • Moderators

behdadsoft, again, read the help file instead of expecting people to spoon feed you everything! At the very least look at the Wiki - Arrays

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...