Computing.Net > Forums > Programming > Auto tidy Desktop using .VBS file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Auto tidy Desktop using .VBS file

Reply to Message Icon

Name: CR
Date: December 13, 2008 at 15:50:10 Pacific
OS: Windows XP Pro SP3
CPU/Ram: AMD XP 2500+ 1GB
Product: Custom / CUSTOM BUILD
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: BatchFreak
Date: December 13, 2008 at 17:10:53 Pacific
Reply:

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.


0

Response Number 2
Name: CR
Date: December 13, 2008 at 17:16:12 Pacific
Reply:

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?


0

Response Number 3
Name: BatchFreak
Date: December 13, 2008 at 17:18:42 Pacific
Reply:

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.


0

Response Number 4
Name: CR
Date: December 13, 2008 at 17:20:40 Pacific
Reply:

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 :)


0

Response Number 5
Name: BatchFreak
Date: December 13, 2008 at 17:24:02 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: CR
Date: December 13, 2008 at 17:57:23 Pacific
Reply:

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


0

Response Number 7
Name: BatchFreak
Date: December 13, 2008 at 21:25:58 Pacific
Reply:

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.


0

Response Number 8
Name: CR
Date: December 14, 2008 at 15:54:50 Pacific
Reply:

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


0

Response Number 9
Name: CR
Date: December 16, 2008 at 02:15:33 Pacific
Reply:

Anyone...?


0

Response Number 10
Name: MrRoboto
Date: February 4, 2009 at 10:58:00 Pacific
Reply:

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


0

Response Number 11
Name: CR
Date: February 6, 2009 at 17:32:18 Pacific
Reply:

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...


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Auto tidy Desktop using .VBS file

Opening specific files using vb www.computing.net/answers/programming/opening-specific-files-using-vb-/4263.html

VB file name parser and sorter www.computing.net/answers/programming/vb-file-name-parser-and-sorter/15622.html

Delete folders using .vbs script www.computing.net/answers/programming/delete-folders-using-vbs-script/10767.html