Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi all, I posted this earlier but it seems to have been removed without notification for some reason.... Anyway, I am using Windows XP Pro and have been trying to use a .VBS file I found floating around Google to auto tidy the desktop (as I don't know anything about .VBS myself).
By this I mean create a folder called 'Tidy Desktop then move everything such as any stray files, folders, shortcuts, etc... (except the default 'special' folders such as My Computer, My Files, and the Recycle Bin).
This is what I have so far:
Const DESKTOP = &H10&Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(DESKTOP)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.PathstrComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & strpath & "'} Where " _
& "ResultClass = CIM_DataFile")Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile in colFiles
strDesktopFolder = strPath & "\" & objFile.Extension
If objFSO.FolderExists(strDesktopFolder) Then
strTarget = strDesktopFolder & "\"
objFSO.MoveFile objFile.Name, strTarget
Else
Set objFolder = objFSO.CreateFolder(strDesktopFolder)
strTarget = strDesktopFolder & "\"
objFSO.MoveFile objFile.Name, strTarget
End If
NextThe problem is, the above .VBS file sorts all files into their file type and puts them into their own folders... I just need it to place all files into the one single folder called 'Tidy Desktop'.
Can anyone help with this?

Here, I seem to be helping you alot :)
MD "C:\documents and settings\USERNAME\Desktop\Tidy Desktop"
MOVE "C:\documents and settings\USERNAME\Desktop\*.*" "C:\documents and settings\USERNAME\Desktop\Tidy Desktop"MY computer, Documents and the Recycle Bin are special and are not regonised by CMD. Try it :) Open up your CMD and type in DIR desktop
It won't show them :)I only Batch if possible, 2000 more lines of code, oh well.

Hi BatchFreak, you sure do and I thank you for your super human brains each time hehe - thank you again :)
But this time I am looking for a .VBS not a Windows Batch file... Any way of altering the above file (from my inital post) to move everything to the one Tidy Desktop folder?

Sorry I don't work with VBS, in your original post you said VBS or BATCH... I'm really stumped on this one, seems like alot of work for something that requires two lines :P
I only Batch if possible, 2000 more lines of code, oh well.

P.S.
You batch will not work as it does not move folders... This is why I initially went to use Robocopy but this also has it's faults too... Hence the .VBS file ;)
However, if you can suggest a way of making the batch version also move folders then I'll be one happy bunny :)

MD "C:\documents and settings\USERNAME\Desktop\Tidy Desktop"
MOVE "C:\documents and settings\USERNAME\Desktop\*.*" "C:\documents and settings\USERNAME\Desktop\Tidy Desktop"
MOVE "C:\documents and settings\USERNAME\Desktop\*" "C:\documents and settings\USERNAME\Desktop\Tidy Desktop"I only Batch if possible, 2000 more lines of code, oh well.

Hi, the last line you added just gives the following error:
The filename, directory name, or volume label syntax is incorrect.

ROBOCOPY "C:\documents and settings\\administrator\\desktop\\" "C:\documents and settings\\administrator\\desktop\\TIDY" *.* /E /move
THIS will move all of you files and folders to a folder called TIDY for some odd reason though the dir tree ends up like this....
C:\documents and.........\desktop\tidy\tidy\filesI only Batch if possible, 2000 more lines of code, oh well.

Thanks BatchFreak, but I have already tried Robocopy. It might just be me but when using it any commands after don't seem to get done...
I.E.
After the Tidy Desktop command has been done using Robocopy my batch then copies a log file from my USB Key to the users Desktop, or it is meant to but this command seems to get skipped after Robocopy has done It's thing. However, the rest of my batch then works without fault...This is the last part of my batch:
REM Tidy Desktop
Commands\ROBOCOPY "%systemdrive%\Documents and Settings\%USERNAME%\Desktop" "%systemdrive%\Documents and Settings\%USERNAME%\Desktop\Tidy Desktop (%USERNAME%'s files)" /S /MOVE > NULIF EXIST "%FILENAME%" MOVE /Y "%FILENAME%" "%systemdrive%\Documents and Settings\%USERNAME%\Desktop\" > NUL
Strange thing is that if I remove the Robocopy part then the log file is correctly copied to the users Desktop? I have even tried adding a pause in there just after to make sure Robocopy has finished but It is still the same.
This is why I was asking about the .VBS file below to see if anyone knows how to adjust it to copy the entire contents of the users Desktop to a Tidy Desktop folder.
Const DESKTOP = &H10&Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(DESKTOP)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.PathstrComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & strpath & "'} Where " _
& "ResultClass = CIM_DataFile")Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile in colFiles
strDesktopFolder = strPath & "\" & objFile.Extension
If objFSO.FolderExists(strDesktopFolder) Then
strTarget = strDesktopFolder & "\"
objFSO.MoveFile objFile.Name, strTarget
Else
Set objFolder = objFSO.CreateFolder(strDesktopFolder)
strTarget = strDesktopFolder & "\"
objFSO.MoveFile objFile.Name, strTarget
End If
Next

To get that script to work the way you want you just need to change the following line:
strDesktopFolder = strPath & "\" & objFile.Extensionto:
strDesktopFolder = strPath & "\Tidy Desktop"The whole script:
Const DESKTOP = &H10& Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace(DESKTOP) Set objFolderItem = objFolder.Self strPath = objFolderItem.Path strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer _ & "\root\cimv2") Set colFiles = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_Directory.Name='" _ & strpath & "'} Where " & "ResultClass = CIM_DataFile") Set objFSO = CreateObject("Scripting.FileSystemObject") For Each objFile in colFiles strDesktopFolder = strPath & "\Tidy Desktop" If objFSO.FolderExists(strDesktopFolder) Then strTarget = strDesktopFolder & "\" objFSO.MoveFile objFile.Name, strTarget Else Set objFolder = objFSO.CreateFolder(strDesktopFolder) strTarget = strDesktopFolder & "\" objFSO.MoveFile objFile.Name, strTarget End If Next

Hi MrRoboto, thank you sooo much for your reply - now that I see the code I don't know how I missed that simple edit lol.
Anyway, thank you again :) I will test it after I've finished downloading the Windows 7 beta from Microsoft ;) as it just says my Desktop is locked till it has finished sigh...

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |