VBA- Deleting a file problem...

  • Thread starter Thread starter Mel
  • Start date Start date
M

Mel

'Anyone know of a way to run a command line from within PPT without
calling to an external BAT or CMD file? I'm trying to simply delete
some folders within which is an addin that my code already unloaded
and removed and unregistered, and now I want its folders deleted
(within the same PPT session that started the macro). But PPT holds on
to the addin file thinking it's still being used (which it's not) and
won't let RmDir or Kill code remove it. BUT I can make it run a CMD
file consisting of "RMDIR C:\foldername /s /q" and it works fine. The
problem is due to technicalities, I'd rather not use an external file.
Is there another way?

Thanks,
Melina
 
Mel said:
'Anyone know of a way to run a command line from within PPT without
calling to an external BAT or CMD file? I'm trying to simply delete
some folders within which is an addin that my code already unloaded
and removed and unregistered, and now I want its folders deleted
(within the same PPT session that started the macro). But PPT holds on
to the addin file thinking it's still being used (which it's not) and
won't let RmDir or Kill code remove it. BUT I can make it run a CMD
file consisting of "RMDIR C:\foldername /s /q" and it works fine. The
problem is due to technicalities, I'd rather not use an external file.
Is there another way?

Amazing that RMDIR works! But, if it does, you don't *have* to run it
via a CMD file. You can just do something like:

Dim cmd As String
cmd = "RMDIR C:\foldername /s /q"
Shell Environ("comspec") & " /c " & cmd

Something like that, at any rate...
 
Wow, that was too easy, Karl! I tested it and it worked. There was no
need to use an external CMD file. That seems too easy, but I love it.

Can anyone think of drawbacks or gotcha's for doing it that way?

And what's the difference in these two ways of coding it?

Shell Environ("comspec") & " /c " & cmd

Call Shell (Environ$ ("COMSPEC") & " /c " & cmd)

Thanks,
Melina
 
Steve said:
You need to be aware that once you launch a process with SHELL, the rest of
your code continues to run.

Of course, but that's the same proposition he was facing originally,
right? There are a lot of ways you can do a "shell and wait" routine,
if that's needed, though.
 
Mel said:
Wow, that was too easy, Karl! I tested it and it worked. There was no
need to use an external CMD file. That seems too easy, but I love it.

Can anyone think of drawbacks or gotcha's for doing it that way?

Like Steve pointed out, it's asynchronous, so if you have multiple
commands that each depend on the previous one being completed first,
you'll need to start looking at that CMD file again. Or, look for
"shell and wait" algorithms. (http://vb.mvps.org/samples/Shell32)
 
Back
Top