Login | |
|
 |
RE: desktop deleting some file script - 9/7/2005 7:37:53 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
To delete the files from the desktop, you will have to get a files collection containing all the files on the desktop, check each file's name and delete it if it matches your criteria OR if you know the name of the file(s) to be deleted, you can bind directly to the file and delete it. Example1 Option Explicit Dim objFso Dim objShell Dim objFolder Dim colFiles Dim objFile Dim strPathToDesktop Set objFso = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Wscript.shell") strPathToDesktop = objShell.SpecialFolders("Desktop") Set objFolder = objFso.GetFolder(strPathToDesktop) Set colFiles = objFolder.Files For Each objFile In colFiles If UCase(objFile.Name) = "PAPER.XLS" Or _ UCase(objFile.Name) = "SHORTCUT TO PAPER" Or _ UCase(objFile.Name) = "PAPER" Then objFso.DeleteFile objFile.Path,True End If Next Set colFiles = Nothing Set objFolder = Nothing Set objShell = Nothing Set objFso = Nothing Example2 Option Explicit Dim objFso Dim objShell Dim objFile Dim strPathToDesktop Set objFso = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Wscript.shell") strPathToDesktop = objShell.SpecialFolders("Desktop") Set objFile = objFso.GetFile(strPathToDesktop & "\PAPER.XLS") objFile.Delete Set objFile = Nothing Set objShell = Nothing Set objFso = Nothing Example3 Option Explicit Dim objFso Dim objShell Dim strPathToDesktop Set objFso = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Wscript.shell") strPathToDesktop = objShell.SpecialFolders("Desktop") objFso.DeleteFile strPathToDesktop & "\PAPER.XLS" Set objShell = Nothing Set objFso = Nothing HTH remarks: - there doesn't exist a function named HCase() I think you wanted to use UCase, which converts a string to uppercase - if you use the function LCase, which converts a string to lower case, you will never have a match if the other string is in uppercase. LCase(objFile.Name) = "PAPER.XLS" will never find a match, you should use it like this: LCase(objFile.Name) = "paper.xls"
< Message edited by Zifter -- 9/7/2005 7:45:53 PM >
|
|
| |
|
|
|
 |
RE: desktop deleting some file script - 9/7/2005 8:24:18 PM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
In the beginning of the script the objects are created. Then the objects are used. And finally the objects are destroyed again (by setting them to Nothing). If we don't specifically destroy the objects, they remain in memory with the risk of interfering with other scripts or maybe even use all available memory (which isn't very likely to happen, but theoretically it can) The functions UCase() and LCase() convert a string into respectively uppercase and lower case, it doesn't matter what case the original string is in. Wscript.Echo UCase("tHIs iS A TESt sTRinG") Output: THIS IS A TEST STRING Wscript.Echo LCase("tHIs iS A TESt sTRinG") Output: this is a test string HTH
|
|
| |
|
|
|
 |
RE: desktop deleting some file script - 9/8/2005 1:55:30 AM
|
|
 |
|
| |
Zifter
Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
|
Can you post the script, maybe it's just some small typing mistake...
|
|
| |
|
|
|
 |
RE: desktop deleting some file script - 9/8/2005 7:44:46 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
|
This line should fail due to lack of quotes: link.TargetPath = \\Server1\Local Drive\Storage\house\paper.xls Do you have On Error Resume next in your script? If so, remove it to see what the errors are.
|
|
| |
|
|
|
 |
RE: desktop deleting some file script - 9/8/2005 8:29:07 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
|
Are you doing this as a webpage/HTA, or a .vbs file?
|
|
| |
|
|
|
 |
RE: desktop deleting some file script - 9/8/2005 11:26:35 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
|
What error does it give you?
|
|
| |
|
|
|
 |
RE: desktop deleting some file script - 9/8/2005 3:25:32 PM
|
|
 |
|
| |
binHEX
Posts: 9
Score: 1
Joined: 9/2/2005
Status: offline
|
When you put Option Explicit at the beginning of your script, one of the things it does is force you to DIM all of your variables, prior to using them. And since you weren't DIM'ing all of your variables, it was erroring out on ya. I reworked your script real fast, and it should work now, but I haven't tested it, so.... No Warranty, Express or Implied, , your mileage may vary, item may differ in appearance from the picture on the box, objects are closer than they appear, yadda yadda.... Instead of using IF...THEN statements to test for like 5 or 6 diff things one after another, try using SELECT CASE...CASE statements. They run faster, and they look cooler - which is what is really important. After all, we're geeks. ANYTHING that we can do to look cooler is a Good Thing, right? Option Explicit Dim oFS, oWsh, oNetwork, strUser Dim DesktopPath, link Dim folder, file, icon1, icon2, icon3, icon4 Set oWsh = CreateObject("WScript.Shell") set oFS = WScript.CreateObject("Scripting.FileSystemObject") Set oNetwork= CreateObject("Wscript.Network") Set Shell = CreateObject("WScript.Shell") strUser = oNetwork.UserName DesktopPath = oShell.SpecialFolders("Desktop") Set link = Shell.CreateShortcut(DesktopPath & "\Paper List.lnk") link.TargetPath = "\\Server1\Local Drive\Storage\house\paper.xls" link.Save icon1 = UCase(oWsh.SpecialFolders("Desktop") & "\PAPER.XLS.lnk") icon2 = UCase(oWsh.SpecialFolders("Desktop") & "\Shortcut to PAPER.lnk") icon3 = UCase(oWsh.SpecialFolders("Desktop") & "\PAPER.lnk") icon4 = UCase(oWsh.SpecialFolders("Desktop") & "\ABC PAPER LIST.XLS.lnk") Set folder = oFS.GetFolder(DesktopPath) For Each file In folder.Files Select Case UCase(file) Case icon1 oFS.DeleteFile(file) Case icon2 oFS.DeleteFile(file) Case icon3 oFS.DeleteFile(file) Case icon4 oFS.DeleteFile(file) Case Else End Select Next WScript.Quit (0) Have fun! binHEX
< Message edited by binHEX -- 9/8/2005 3:30:33 PM >
|
|
| |
|
|
|
 |
RE: desktop deleting some file script - 9/9/2005 2:56:51 AM
|
|
 |
|
| |
kracksmith
Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
|
ok it works now. the "shell" needed to be DIM and there was a typo "oShell" that needs to be changed to just "Shell" Option Explicit Dim oFS, oWsh, oNetwork, strUser, Shell Dim DesktopPath, link Dim folder, file, icon1, icon2, icon3, icon4 Set oWsh = CreateObject("WScript.Shell") set oFS = WScript.CreateObject("Scripting.FileSystemObject") Set oNetwork= CreateObject("Wscript.Network") Set Shell = CreateObject("WScript.Shell") strUser = oNetwork.UserName DesktopPath = Shell.SpecialFolders("Desktop") Set link = Shell.CreateShortcut(DesktopPath & "\Paper List.lnk") link.TargetPath = "\\Server1\Local Drive\Storage\house\paper.xls" link.Save icon1 = UCase(oWsh.SpecialFolders("Desktop") & "\PAPER.XLS.lnk") icon2 = UCase(oWsh.SpecialFolders("Desktop") & "\Shortcut to PAPER.lnk") icon3 = UCase(oWsh.SpecialFolders("Desktop") & "\PAPER.lnk") icon4 = UCase(oWsh.SpecialFolders("Desktop") & "\ABC PAPER LIST.XLS.lnk") Set folder = oFS.GetFolder(DesktopPath) For Each file In folder.Files Select Case UCase(file) Case icon1 oFS.DeleteFile(file) Case icon2 oFS.DeleteFile(file) Case icon3 oFS.DeleteFile(file) Case icon4 oFS.DeleteFile(file) Case Else End Select Next WScript.Quit (0)
|
|
| |
|
|
|
 |
RE: desktop deleting some file script - 9/9/2005 4:38:52 PM
|
|
 |
|
| |
binHEX
Posts: 9
Score: 1
Joined: 9/2/2005
Status: offline
|
My bad. I preach at you for not DIM'ing your variables, an then I turn around and do the same thing.
|
|
| |
|
|
|
|
|