Auto tidy Desktop using .VBS file

Custom / CUSTOM BUILD
December 13, 2008 at 15:50:10
Specs: Windows XP Pro SP3, AMD XP 2500+ 1GB
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.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 & "\" & 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

The 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?


See More: Auto tidy Desktop using .VBS file

Report •


#1
December 13, 2008 at 17:10:53
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.


Report •

#2
December 13, 2008 at 17:16:12
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?


Report •

#3
December 13, 2008 at 17:18:42
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.


Report •

Related Solutions

#4
December 13, 2008 at 17:20:40
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 :)


Report •

#5
December 13, 2008 at 17:24:02
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.


Report •

#6
December 13, 2008 at 17:57:23
Hi, the last line you added just gives the following error:
The filename, directory name, or volume label syntax is incorrect.

Report •

#7
December 13, 2008 at 21:25:58
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\files

I only Batch if possible, 2000 more lines of code, oh well.


Report •

#8
December 14, 2008 at 15:54:50
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 > NUL

IF 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.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 & "\" & 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


Report •

#9
December 16, 2008 at 02:15:33
Anyone...?

Report •

#10
February 4, 2009 at 10:58:00
To get that script to work the way you want you just need to change the following line:
strDesktopFolder = strPath & "\" & objFile.Extension

to:

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


Report •

#11
February 6, 2009 at 17:32:18
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...


Report •


Ask Question