#71700 - 2002-11-21 11:12 AM
The RD command
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
Has anyone managed to get the RD command to function in a Kix Script?
I am trying to delete certain directories and nothing, but nothing happens. Is it my script?
code:
$liste_postes="\\sntfic03\echange\adminflux\postes.txt" IF Open(1,$liste_postes) = 0 $machines=ReadLine(1) WHILE @ERROR=0 $lehman_mesdoc="\\$machines\c$\mes documents\leh_data" RD "$lehman_mesdoc" $machines=ReadLine(1) LOOP ENDIF close(1) EXIT(1)
I ran a test to see if it was reading the file contain the machine names correctly and it is, but the script refuses to do what I want it to do.
I thought maybe the problem was because the directory was not empty, but I made an empty test directory and the script didn't delete it.
Anyone have an idea?
Thx in advance, Z. [ 21. November 2002, 11:14: Message edited by: zdarma ]
|
|
Top
|
|
|
|
#71701 - 2002-11-21 11:21 AM
Re: The RD command
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Try printing the error value after the RD - that may give you a clue.
code:
RD "$lehman_mesdoc" If @ERROR "Cannot remove directory: " @ERROR "/" @SERROR ? EndIf
|
|
Top
|
|
|
|
#71703 - 2002-11-21 01:51 PM
Re: The RD command
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Uh, J, guess you read the original post too quickly and missed this bit: quote: I thought maybe the problem was because the directory was not empty, but I made an empty test directory and the script didn't delete it.
Still, the SHELL solution is appropriate if there are files left in the directory.
|
|
Top
|
|
|
|
#71705 - 2002-11-21 02:26 PM
Re: The RD command
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
I added the error code like u suggested. It tells me that it can't find the directory. Which is bizarre, because just before I do the error code check, I have it print out the directory where it is going to and it has no problem showing me the correct path. However, when it comes time to delete it, it's a big NYET.
Jpols, I was doing a lot better before I tried to delete this simple little directory
I am using Kix 4.12. I thought about the fact that in Kix 4.11 u couldn't delete a directory that wasn't empty, hence the empty directory test. I even had the shell command in, in the original script, but I coudln't get it to work. I used the shell command u added to the post and it still doesn't work. I use the error flag to see what is happenening and as I said before it doesn't seem to find the directory.
Thanks for all the help guys but if u got anymore suggestions, I'm open for business. I'll keep trying to make it work, if I find a solution I'll let u know.
Z.
|
|
Top
|
|
|
|
#71706 - 2002-11-21 02:37 PM
Re: The RD command
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
One more thing. Is it normal the error code (level 2) returned tells me it can't find the file? Shouldn't I get at the very least directory not found?
I get this error whether I try to delete an empty directory using RD within the script or if I use the RD command from a shell command.
thx
|
|
Top
|
|
|
|
#71708 - 2002-11-21 02:46 PM
Re: The RD command
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
I didn't look too closely at your code before, but...
You are expanding variables inside this string:
code:
$lehman_mesdoc="\\$machines\c$\mes documents\leh_data"
This is fine for $machines, because that is exactly what you want to do. But what about the "c$"? What do tyou think that "$" there might expand to?
Try changing the line to:
code:
$lehman_mesdoc="\\$machines\c$$\mes documents\leh_data"
Using "$$" explicitly states that you want a "$" in the string, not a variable to be expanded.
The reason you are getting the error 2 is because the resultant path is not what you expected it to be and it really can't find it.
Try displaying the path after you have created it, and you will see what I mean.
This is a good example of why you should include error checking, even when you are sure that you don't need it ![[Wink]](images/icons/wink.gif) [ 21. November 2002, 14:48: Message edited by: Richard Howarth ]
|
|
Top
|
|
|
|
#71710 - 2002-11-22 08:48 AM
Re: The RD command
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
And the winning line to make the script work was
code:
shell '%comspec% /c RD /S /Q "\\$machines\c$$\mes documents\leh_data" + >nul 2>nul'
However, what I don't understand is why I need to put the double '$' after the C. I have other scripts using 'C$' and they function correctly. I figured that because I was shelling out, the script would see C$ as a hidden share (which it is) and that I wouldn't need to put in the double $.
I even put the double $ into my original script that I posted here and that seems to work fine. Has anyone else seen this anomalie with Kix 4.12. All my other scripts were written using 4.11.
Thanks to all for their help.
Z.
|
|
Top
|
|
|
|
#71713 - 2002-11-22 09:11 AM
Re: The RD command
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
I don't declare anywhere $=dir(), but and this is a big but I do have Explicit set to ON, because I had a typo in a previous script variable and for the life of me I couldn't figure out why my script wasn't working, until Jpols pointed out that I had made a spelling mistake either in the declared variable or when I tried to use the variable and suggested I use Explicit to prevent such problems in the future.
I didn't know that by turning Explicit ON, it would affect the hidden C$ share. Live and learn, live and learn.
Thx
|
|
Top
|
|
|
|
#71714 - 2002-11-22 09:19 AM
Re: The RD command
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
... and here's the corresponding quote from manual :
quote: By default, references to variables inside strings (e.g.: “String with a $Var in it.”) are also resolved before the string is displayed. The only exceptions to this rule are arrays and object references, which can not be used inside strings. To use arrays or object references in combination with strings, you have to use concatenation. Note that you can disable resolving of variables inside strings using the NoVarsInStrings option (see SetOption for full details).
--------------------------------------------------------------------------------
Note: The characters @, %, or $ are normally used to indicate macros, environment strings, or variables. If you want to use these characters in a string, use @@, %%, or $$.
--------------------------------------------------------------------------------
_________________________
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 657 anonymous users online.
|
|
|