#193027 - 2009-03-20 09:14 AM
How to delete an folder?
|
Solid
Fresh Scripter
Registered: 2009-02-13
Posts: 15
Loc: The Netherland
|
I want to delete automatically a file.
IF exist (%userprofile% +"Application Data\Microsoft\Internet Explorer\Quick Launch\test1")
DEL "%userprofile%\Application Data\Microsoft\Internet Explorer\Quick Launch\test1"
ELSE
MESSAGEBOX ("Have a nice day.")
ENDIF
But the kixtart script doesn’t delete the file.
Edited by Solid (2009-03-20 09:16 AM)
|
|
Top
|
|
|
|
#193029 - 2009-03-20 09:24 AM
Re: How to delete an folder?
[Re: Richard H.]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Something like this:
$sToDelete=%userprofile% +"Application Data\Microsoft\Internet Explorer\Quick Launch\test1"
IF Exist($sToDelete)
DEL $sToDelete
IF @ERROR "Cannot delete '"+$sToDelete+"'"+@CRLF+"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
ELSE
MESSAGEBOX ("Have a nice day.")
ENDIF
|
|
Top
|
|
|
|
#193031 - 2009-03-20 11:02 AM
Re: How to delete an folder?
[Re: Richard H.]
|
Solid
Fresh Scripter
Registered: 2009-02-13
Posts: 15
Loc: The Netherland
|
The folder delete worked, but the file deleting didn’t work? I even included the error message and its tells me everything went correctly but the file still exist.
|
|
Top
|
|
|
|
#193032 - 2009-03-20 11:05 AM
Re: How to delete an folder?
[Re: Solid]
|
Solid
Fresh Scripter
Registered: 2009-02-13
Posts: 15
Loc: The Netherland
|
$sToDelete= %userprofile% +"Application Data\Microsoft\Internet Explorer\Quick Launch\test1"
$Folder= "c:\testtest\test\"
IF Exist($sToDelete)
DEL $sToDelete
IF @ERROR "Cannot delete '"+$sToDelete+"'"+@CRLF+"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
ENDIF
ENDIF
IF Exist ($Folder)
RD $Folder
IF @ERROR "Cannot delete '"+$Folder+"'"+@CRLF+"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
ENDIF
ENDIF
Edited by Solid (2009-03-20 11:07 AM)
|
|
Top
|
|
|
|
#193037 - 2009-03-20 01:12 PM
Re: How to delete an folder?
[Re: Glenn Barnas]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Well, I see a couple of issues.. (besides the double spaces).
What is "test" - a file or folder? It doesn't have an extension like most files would, so the assumption might be it's a folder, but you try to DEL it, so it must be a file.. It would be pretty unusual for a file on a Windows system NOT to have an extension, so I'm guessing you have "hide extensions" enabled in explorer (bad idea, BTW) and don't know that it actually has an extension.
Considering the location on the QL bar, it's likely a .lnk file - when I open a command prompt and navigate to that location, a DIR tells me that the folder is filled with .LNK files, but no folders.
The codeDel 'aFileThatDoesNotExist' @SERROR ? always returns a success message. This also is an issue, since your code never checks to see if the file of interest actually exists - it relies on the exit status of the command, which you clearly haven't tested for functionality within the scope of your design.
When things don't work as expected, STOP TESTING YOUR CODE and start testing the COMPONENTS of your code. Simplify! It's easier to troubleshoot 1-2 lines of code than an entire script.- Create small scriptlets with single processes.. when they work, combine them into a larger package. If they don't work, check the manual and compare that with your understanding of the command(s).
- Work at the command prompt when developing code - unlike the GUI (which (by default) treats you like a moron and hides all kind of important information unless you configure it otherwise) - the command prompt does not lie or mislead. Browse to the Quick Launch folder in Explorer - what do you see? Open a command prompt, type
CD "%APPDIR%\Internet Explorer\QuickLaunch
Dir What do you see there? Does it exactly match what Explorer shows you? I doubt it. - Add debugging messages that identify the results, or even run the commands a second time to display the results on the screen. Don't assume what's being assigned to a variable - KNOW!
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#193051 - 2009-03-20 09:37 PM
Re: How to delete an folder?
[Re: Glenn Barnas]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Details, Details...
|
|
Top
|
|
|
|
#193062 - 2009-03-23 10:31 AM
Re: How to delete an folder?
[Re: Solid]
|
Solid
Fresh Scripter
Registered: 2009-02-13
Posts: 15
Loc: The Netherland
|
Thank you Glenn for your advise on the file extension that help allot, after that I changed the code from
$sToDelete= %userprofile% +"Application Data\Microsoft\Internet Explorer\Quick Launch\test1"
to
$sToDelete= "%userprofile%\Application Data\Microsoft\Internet Explorer\Quick Launch\test1.lnk"
Then the script did its job. BTW I have version 4.51 so the RD /s wont work but that was not necessary.
Edited by Solid (2009-03-23 10:32 AM)
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 400 anonymous users online.
|
|
|