Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The System Cannot Find The File Specified 2

Status
Not open for further replies.

NFI

Programmer
Jun 7, 2000
278
GB
Hello,

I am writing a script to delete user Profile Directory Trees and User Data directory Trees. I am getting error 80070002 "The System Cannot Find The File Specified". This is what my code looks like:

Code:
If objFSO.FolderExists(strUserPath) Then
 strCmd = "rd /s /q " & strUserPath
 iRC = objShell.Run(strCmd,0,TRUE)
End If

objFSO is an instance of the WScript.FileSystemObject object
objShell is an instance of the Wscript.Shell object
strUserPath is the full path including drive letter of the directory I want to delete

I'm running the script interactively as the domain admin on the server itself and, frustratingly, I can happily carry out the above shell command manually, just not from this script...

You might think that, seeing as the FSO is happy that the folder exists, getting the error I'm getting shouldn't be possible...

I thought this might be a permissions related problem and that the .Shell object just wasn't returning the right error, so I've given the directory I want to delete Full Control to Everybody, but it makes no difference.

If anybody has any ideas, I'd be very happy to hear them.

Thanks,

Paul
 
You may try this:
strCmd = "cmd /c rd /s /q """ & strUserPath & """"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
perhaps a "\" needs to be added or removed from the end, but i think PHV is on the right lines
 
Hi chaps,

that works - thanks for that :)

So why does this work and the way I was doing it not work?


Thanks again,

Paul
 
because your string strUserPath had white space in it, so, the shell read your "rd /s /q " & strUserPath as something like

rd /s /q D:\Hello World

it would be looking for folder D:\Hello and would think/ignore there was an extra parameter World passed to it,,which i guess it would ignore in this case
 
sorry,
but if you put " round it then the shell knows to treat your last parameter correctly
 
Doh - of course :(

Thanks for that,

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top