Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-03

Deleting the current directory (after changing it)

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rich Pasco

Removing the current directory

Back in the good old days of 16-bit Borland Pascal under DOS I had a utility which (among other things) would change directory to the parent and the delete the old working directory. It worked perfectly. A simplified listing appears below.

But when I compile it for Win 32 under Free Pascal and run it under Windows 2000, it crashes with Access Denied (Runtime error 5) when it tries to delete the old current directory.

As I recall, this problem was previously noted in this forum and it was explained that, although the program has changed its own working directory to the parent, the command shell in which it runs is still using the working directory that it was when the program was first launched.

OK, that's all well and good, but I miss the functionality of my little utility, and I want to get it back. Can anyone suggest a workaround that really does work?

- Rich

uses
  DOS;
var
  victim: string;
begin
  victim := FExpand('.');
  chdir ('..');
  WriteLn('Current directory:  '+FExpand('.'));
  WriteLn('Removing directory: '+victim);
  rmdir(victim);
end.
Peter Vreman
Show quoted text 20 lines
Removing the current directory Back in the good old days of 16-bit Borland Pascal under DOS I had a utility which (among other things) would change directory to the parent and the delete the old working directory. It worked perfectly. A simplified listing appears below. But when I compile it for Win 32 under Free Pascal and run it under Windows 2000, it crashes with Access Denied (Runtime error 5) when it tries to delete the old current directory. As I recall, this problem was previously noted in this forum and it was explained that, although the program has changed its own working directory to the parent, the command shell in which it runs is still using the working directory that it was when the program was first launched. OK, that's all well and good, but I miss the functionality of my little utility, and I want to get it back. Can anyone suggest a workaround that really does work?

A batchfile ?

Rich Pasco
to Peter Vreman
Peter Vreman wrote
A batchfile ?

We all know there are severe limitations in BAT as a programming language. I want to do much more than just switch to the parent and then delete the old current directory (I omitted the rest from my example because it was irrelevant to my question). However, just for the sake of argument (and getting a little off-topic here), can you exhibit a BAT file that will do it (switch to the parent and then delete the old current directory)?

You obviously can't do
RD .
CD ..
because you can't remove the current directory.

Suppose you try to do
CD ..
RD --now what?--

How do you preserve the name of the initial working directory to use it as the argument for the subsequent RD?

- Rich