Page 1 of 1 1
Topic Options
#71700 - 2002-11-21 11:12 AM The RD command
zdarma Offline
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 Offline
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
#71702 - 2002-11-21 01:44 PM Re: The RD command
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Z,

how youre doin ?

Thats because KiX' RD can't delete directories unless they are empty [Mad] !!! (Hmm ... haven't tried 4.12 yet)

Try instead

something like :

code:
shell '%ComSpec% /c rd /S /Q ' + $lehman_mesdoc + ' >nul 2>nul'



[ 21. November 2002, 13:46: Message edited by: jpols ]
_________________________



Top
#71703 - 2002-11-21 01:51 PM Re: The RD command
Richard H. Administrator Offline
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
#71704 - 2002-11-21 01:59 PM Re: The RD command
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Crap, yes Richard !

speed reader today [Roll Eyes]
_________________________



Top
#71705 - 2002-11-21 02:26 PM Re: The RD command
zdarma Offline
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 [Mad]

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 [Frown] 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 Offline
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
#71707 - 2002-11-21 02:42 PM Re: The RD command
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
It tells 2 amyway (also in not finding registry keys)

Ok,

What if you replace this :

quote:

$lehman_mesdoc="\\$machines\c$\mes documents\leh_data"

with this :

code:
$lehman_mesdoc="\\" + $machines + "\c$$\mes documents\leh_data"

additionally check if your list contains more than the Computer names ... just wild guessing here though

Hey, and what is with the space in path ? Tried additional quotes ?

[ 21. November 2002, 14:45: Message edited by: jpols ]
_________________________



Top
#71708 - 2002-11-21 02:46 PM Re: The RD command
Richard H. Administrator Offline
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]

[ 21. November 2002, 14:48: Message edited by: Richard Howarth ]

Top
#71709 - 2002-11-21 02:48 PM Re: The RD command
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
hehe,

by 4 minutes Richard ! [Razz]
_________________________



Top
#71710 - 2002-11-22 08:48 AM Re: The RD command
zdarma Offline
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
#71711 - 2002-11-22 09:03 AM Re: The RD command
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
shouldn't be any change between the versions.
anyway, if your script has somewhere $ set as variable:
$=dir()

as for example, that will convert the $ to anything it might be. thus destroying your line.
_________________________
!

download KiXnet

Top
#71712 - 2002-11-22 09:04 AM Re: The RD command
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Z,

the double quotes to make the path with spaces inside worky ...

normally you don't have problems with single dollar signs unless you nullify a statement with $ = function ($ gets defined) OR of course with explicit on !

By default KiXtart tries to expand any variable so best practice is to get used to say $$ if you want to use it as character same is valid for @@ and %% ...

J.
_________________________



Top
#71713 - 2002-11-22 09:11 AM Re: The RD command
zdarma Offline
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. [Eek!] Live and learn, live and learn.

Thx

Top
#71714 - 2002-11-22 09:19 AM Re: The RD command
Jochen Administrator Offline
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
Page 1 of 1 1


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

Who's Online
0 registered and 533 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.067 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

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