Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '===================================================================================
- ' Given this structure:
- '
- '│ process.vbs
- '│
- '└───Start
- ' ├───1
- ' │ 123456789012aaa.txt
- ' │ 123456789013bbb.txt
- ' │
- ' ├───2
- ' │ 223456789012ccc.txt
- ' │ 223456789013ddd.txt
- ' │
- ' ├───3
- ' │ 323456789012eee.txt
- ' │ 323456789013fff.txt
- ' │
- ' ├───4
- ' │ 423456789012ggg.txt
- ' │ 423456789013hhh.txt
- ' │
- ' ├───5
- ' │ 523456789012iii.txt
- ' │ 523456789013jjj.txt
- ' │
- ' └───6
- ' 623456789013kkk.txt
- ' 623456789012jjj.txt
- '===================================================================================
- dim strPath : strPath = "Start"
- dim blnDoIt : blnDoIt = false
- '===================================================================================
- dim objFSO : set objFSO = CreateObject("Scripting.FileSystemObject")
- dim objFolder : set objFolder = objFSO.GetFolder(strPath)
- dim strPGetAbsolutePathName : strPGetAbsolutePathName = objFSO.GetAbsolutePathName(strPath)
- dim colSubfolders : set colSubfolders = objFolder.Subfolders
- '===================================================================================
- for each objSubfolder in colSubfolders
- strNameOfFolder = objSubfolder.Name
- wscript.echo "Processing directory: " & strNameOfFolder
- strFileNameToUse = GetFileNameToUseAsParentDir (strNameOfFolder)
- wscript.echo " > Chosen file to represent directory: " & strFileNameToUse
- strLeft12 = left (strFileNameToUse, 12)
- wscript.echo " > First 12 characters of file: " & strLeft12
- if blnDoIt then
- wscript.echo " > Renaming directory " & strPGetAbsolutePathName & "\" & strNameOfFolder & " to " & strPGetAbsolutePathName & "\" & strLeft12
- objFSO.MoveFolder strPGetAbsolutePathName & "\" & strNameOfFolder, strPGetAbsolutePathName & "\" & strLeft12
- else
- wscript.echo " > Rename directory " & strPGetAbsolutePathName & "\" & strNameOfFolder & " to " & strPGetAbsolutePathName & "\" & strLeft12
- end if
- wscript.echo ""
- next
- '===================================================================================
- '===================================================================================
- Function GetFileNameToUseAsParentDir(strDir)
- dim oFiles : Set oFiles = CreateObject("System.Collections.ArrayList")
- for each oFile In objFSO.GetFolder(strPGetAbsolutePathName & "\" & strDir).Files
- oFiles.Add oFile.name
- next
- oFiles.Sort
- GetFileNameToUseAsParentDir = oFiles(0)
- set oFiles = nothing
- End Function
- '===================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement