Is it possible to self destruct the directory of a batch and all its contents?

266 Views Asked by At

I have a batch which copies some files from a directory and then should delete the directory the batch file is in, but it just deletes the contents and not the folder itself. I tried with rmdir and with del. The folder structure is the following:

F:\Copy\
        copy.cmd
        files\
            something.jar
            something2.jar

Copy.cmd should copy the .jar files, to the documents folder of the user and then delete the "Copy" folder, so it leaves no traces and does not occupy disk space, but my solutions always left the empty "Copy" folder.

My three tries

@echo off
title Copy
color 20
Xcopy "%cd%\files" "%userprofile%\Documents"
rmdir %cd%

and

@echo off
title Copy
color 20
Xcopy "%cd%\files" "%userprofile%\Documents"
del %cd%

and like Compo suggested

You cannot remove the directory if it's your current working directory. Just step out of it, then delete it using its absolute or relative path.

@echo off
title Copy
color 20
Xcopy "%cd%\files" "%userprofile%\Documents"
cd ..
rmdir %~dp0 /S 

did not work.

0

There are 0 best solutions below