|
Answer» save below line as myvbs.vbs change line 13 to the target folder also --------------------------------------------------------- Option Explicit On Error Resume Next Dim T dim fs dim folder dim files dim FILE Dim oFSO Dim X
Set fs = CreateObject("Scripting.FileSystemObject") 'Directory you WANT sorted Set folder = fs.GetFolder("c:\myvbs\")
Set files = folder.Files For Each file in files If file.name = "myvbs.vbs" Then rem wscript.echo "oops found myself" Else T = Mid(file.name,1,len(file.name) - 4) MD(T) Set oFSO = CreateObject ("Scripting.FileSystemObject") X = folder & "\" & T & "\" oFSO.MoveFile file.name,X & file.name End IF Next
Private Function MD(X) Dim objFS, objFol Set objFS = CreateObject("Scripting.FileSystemObject") Set objFol = objFS.CreateFolder(X) End functionLooks like your code is creating a folder for each file name. Which is not what the user asked. Of the set of three files, there should only be one folder created and the three files moved to that folder. Also, why not just use .GetBaseName(strPath) instead of stripping the extension with -4. MANY file extensions these days are no longer dot 3.it would be more efficient if it didnt try to make a folder each time, but the outcome is the same. good point with getbasename. i have cleaned it up a little bit and added what you said , also filename is irrelevant now as long as it has a .vbs extension , and it will just run in the folder it is in. ___________________________________
Dim T , fs, folder, files, file ,X , objFol Set fs = CreateObject("Scripting.FileSystemObject") Set folder = fs.GetFolder(WScript.ScriptFullName & "\..") Set files = folder.Files For Each file in files If Not file.name = Wscript.ScriptName Then T = fs.getbasename(file.name) Set objFol = FS.CreateFolder(T) X = folder & "\" & T & "\" FS.MoveFile file.name,X & file.name End IF Nextnot even a thankyou for solving this problem after a YEAR Quote from: jakel on January 17, 2018, 05:14:58 AM not even a thankyou for solving this problem after a year If you are here for teh th4nxx you are in the wrong place.
|