CMD or batch file; Delete the ZIP file with the same name as the current working folder


I have a working directory for example; \ABC123\WIP\ABC_0123456789*.xml. During a process the contents of ABC_0123456789 are ZIPPED outside of the current working directory; so in this example in the WIP folder;

The directory will now look like;

  1. \ABC123\WIP\ABC_0123456789\
  2. \ABC123\WIP\

Is it possible to have a command which will obtain the folder name of "ABC_0123456789" (or current working directory) and "if exists" delete the ZIP "" in the root (directory above)?


Based on your comment, what you need is this:

del "" 2> nul

It will delete zip-file if it exists and has the same name as current working directory. If it doesn't exist, 2> nul will redirect the error message and you won't see it. You can still use the ERRORLEVEL to check if the zip really existed or not (will be 0 if it existed and 1 if it didn't exist).

If you'd rather check first if it exists or not you can use

IF EXIST "" del ""

this will only execute the delete if the zip exists

EDIT2: @LotPings let me notice something I forgot to add. When variables represent (part of) a path, it is very important to surround it with " in case it may contain whitespaces.