Page 1 of 1 1
Topic Options
#193027 - 2009-03-20 09:14 AM How to delete an folder?
Solid Offline
Fresh Scripter

Registered: 2009-02-13
Posts: 15
Loc: The Netherland
I want to delete automatically a file.

 Code:
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
#193028 - 2009-03-20 09:20 AM Re: How to delete an folder? [Re: Solid]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
File or folder? Your heading says one thing, the post another.

The command to delete a folder is RD (documented in the manual) however the folder must be empty.

To find out why you cannot delete a file (or folder) check the value of @ERROR and @SERROR.

Top
#193029 - 2009-03-20 09:24 AM Re: How to delete an folder? [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Something like this:
 Code:
$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 Offline
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 Offline
Fresh Scripter

Registered: 2009-02-13
Posts: 15
Loc: The Netherland
 Code:
$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
#193034 - 2009-03-20 11:53 AM Re: How to delete an folder? [Re: Solid]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
I wonder if having two spaces between "Internet" and "Explorer" in the path has anything to do with the problem?

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193035 - 2009-03-20 12:00 PM Re: How to delete an folder? [Re: Glenn Barnas]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
That's a good thought. You might try and change "Internet Explorer" to "INTERN~1" and see if that makes a difference.
Top
#193036 - 2009-03-20 12:28 PM Re: How to delete an folder? [Re: BradV]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Or even just remove the extra space -
 Code:
"Internet  Explorer" -> "Internet Explorer"
;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193037 - 2009-03-20 01:12 PM Re: How to delete an folder? [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
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 code
 Code:
Del '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
     Code:
    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! \:D

Top
#193044 - 2009-03-20 04:26 PM Re: How to delete an folder? [Re: Glenn Barnas]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
glenn, you long poster, you. :P

took me an hour (almost) to read your post.
either friday is too far gone or your post was really long...
_________________________
!

download KiXnet

Top
#193047 - 2009-03-20 05:11 PM Re: How to delete an folder? [Re: Richard H.]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
 Originally Posted By: Richard H.
The command to delete a folder is RD (documented in the manual) however the folder must be empty.


This was fixed in version 4.52 of KiXtart. The RD command should now properly remove the entire folder and contents.

 Quote:
RD

Action: Removes the directory specified.

Syntax: RD "directory" [/s]

Remarks: The /s parameter will remove the specified directory including all files and subdirectories below it. CAUTION: Just as its command line counterpart, this file will delete all files including those that are hidden, system and/or read-only. Use this command with great care.

Check the value of @ERROR to see if RD was successful.





 Quote:
Release notes for KiXtart 2010 (version 4.52)


New functionality/enhancements:

1) CompareFileTimes has been enhanced so it can operate on open files.

2) RD can now delete an entire directory tree (including any files) using
the new "/s" parameter.

Examples:
RD "c:\somedirectory" ; deletes "somedirectory" unless it contains
; files or subdirectories

RD "c:\somedirectory" /S ; deletes "somedirectory" including any files
; and subdirectories it may contain

NOTE: Just as its commandline counterpart, KiXtart's "RD /s" command
deletes ALL files, including hidden, system and read-only files.
Use this command with great care!

Top
#193048 - 2009-03-20 05:56 PM Re: How to delete an folder? [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
The point was, long post notwithstanding, is that there were key errors and discrepancies in the base logic, and no amount of pointing to alternate commands would resolve the fact that the path was invalid, and the target object was actually a LNK file.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193051 - 2009-03-20 09:37 PM Re: How to delete an folder? [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Details, Details... ;\)
Top
#193053 - 2009-03-21 01:04 AM Re: How to delete an folder? [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
yeah, isn't that where the Devil is? \:o
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193062 - 2009-03-23 10:31 AM Re: How to delete an folder? [Re: Solid]
Solid Offline
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
 Code:
$sToDelete= %userprofile% +"Application Data\Microsoft\Internet Explorer\Quick Launch\test1"

to
 Code:
$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
#193063 - 2009-03-23 11:09 AM Re: How to delete an folder? [Re: Lonkero]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Sorry, I was thinking the actual folder name had two or more spaces in it, not that he typo'd in his script. Use the 8 character contraction would take care of any amount of spaces in the actual folder name.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2924 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.077 seconds in which 0.033 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org