Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '===================================================================================
  2. ' Given this structure:
  3. '
  4. '│   process.vbs
  5. '│
  6. '└───Start
  7. '    ├───1
  8. '    │       123456789012aaa.txt
  9. '    │       123456789013bbb.txt
  10. '    │
  11. '    ├───2
  12. '    │       223456789012ccc.txt
  13. '    │       223456789013ddd.txt
  14. '    │
  15. '    ├───3
  16. '    │       323456789012eee.txt
  17. '    │       323456789013fff.txt
  18. '    │
  19. '    ├───4
  20. '    │       423456789012ggg.txt
  21. '    │       423456789013hhh.txt
  22. '    │
  23. '    ├───5
  24. '    │       523456789012iii.txt
  25. '    │       523456789013jjj.txt
  26. '    │
  27. '    └───6
  28. '            623456789013kkk.txt
  29. '            623456789012jjj.txt
  30. '===================================================================================   
  31.  
  32. dim strPath : strPath = "Start"
  33. dim blnDoIt : blnDoIt = false
  34.  
  35. '===================================================================================
  36. dim objFSO                  : set objFSO = CreateObject("Scripting.FileSystemObject")
  37. dim objFolder               : set objFolder = objFSO.GetFolder(strPath)
  38. dim strPGetAbsolutePathName : strPGetAbsolutePathName = objFSO.GetAbsolutePathName(strPath)
  39. dim colSubfolders           : set colSubfolders = objFolder.Subfolders
  40.  
  41. '===================================================================================
  42. for each objSubfolder in colSubfolders
  43.     strNameOfFolder = objSubfolder.Name
  44.    
  45.     wscript.echo "Processing directory: " & strNameOfFolder
  46.     strFileNameToUse = GetFileNameToUseAsParentDir (strNameOfFolder)
  47.     wscript.echo " > Chosen file to represent directory: " & strFileNameToUse
  48.     strLeft12 = left (strFileNameToUse, 12)
  49.     wscript.echo " > First 12 characters of file: " & strLeft12
  50.    
  51.     if blnDoIt then
  52.        wscript.echo " > Renaming directory " & strPGetAbsolutePathName & "\" & strNameOfFolder & " to " & strPGetAbsolutePathName & "\" & strLeft12
  53.        objFSO.MoveFolder strPGetAbsolutePathName & "\" & strNameOfFolder, strPGetAbsolutePathName & "\" & strLeft12
  54.     else
  55.        wscript.echo " > Rename directory " & strPGetAbsolutePathName & "\" & strNameOfFolder & " to " & strPGetAbsolutePathName & "\" & strLeft12
  56.     end if
  57.     wscript.echo ""
  58. next
  59. '===================================================================================
  60.  
  61. '===================================================================================
  62. Function GetFileNameToUseAsParentDir(strDir)
  63.  
  64.   dim oFiles : Set oFiles = CreateObject("System.Collections.ArrayList")
  65.  
  66.   for each oFile In objFSO.GetFolder(strPGetAbsolutePathName & "\" & strDir).Files
  67.     oFiles.Add oFile.name
  68.   next
  69.  
  70.   oFiles.Sort
  71.  
  72.   GetFileNameToUseAsParentDir = oFiles(0)
  73.  
  74.   set oFiles = nothing
  75.  
  76. End Function
  77. '===================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement