Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

-Newbie- Renaming folders and subfolders with files count

Status
Not open for further replies.

Mauro_

Technical User
Oct 27, 2016
1
IT
I like to create a script that recursively goes through a chose folder and sub folders and renames there folders with the following rules:

-all folder names need to be replaced with count files.


I believe its possible with _FileListToArrayRec and _FileListToArray functions, but how?

e.g. whit this directory tree:

root
├── folder
│ ├── folder
│ │ ├─ file
│ │ ├─ file
│ │ └─ file
│ ├── folder
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ └── folder
├── folder
│ ├── folder
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ ├── folder
│ │ ├─ file
│ │ ├─ file
│ └── folder
│ ├── folder
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ ├── folder
│ └── folder
├── folder
│ └─ file
└── folder
├─ file
├─ file
└─ file

would produce this output:

root
├── folder(3)
│ ├── folder(3)
│ │ ├─ file
│ │ ├─ file
│ │ └─ file
│ ├── folder(5)
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ └── folder(0)
├── folder(3)
│ ├── folder(4)
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ ├── folder(2)
│ │ ├─ file
│ │ ├─ file
│ └── folder(3)
│ ├── folder(4)
│ │ ├─ file
│ │ ├─ file
│ │ ├─ file
│ │ └─ file
│ ├── folder(0)
│ └── folder(0)
├── folder(1)
│ └─ file
└── folder(3)
├─ file
├─ file
└─ file


Sorry for my bad english. Thanks
Mauro_
 
Here you go, this does what you requested for a single folder.
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Test\")
FileCount = objFolder.Files.Count
objFSO.MoveFolder objFolder.Path, objFolder.Path & FileCount

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top