Question

I am trying to write a batch script to delete files listed in in a text file. I have it working fine (have never written a batch script). The problem is, I can't seem to figure out how to write it using relative paths so that it can be run on a different computer from the root directory.

The batch script I have is:

for /f "delims=" %%f in (List_of_Files.txt) do del "%%f" 

The list of files is structured like this:

payroll_page\cf2_2.gif
payroll_page\chart_e.gif
payroll_page\dollar-06.gif
payroll_page\calendar_files\image001.png

What I want to do is to be able to run this batch file from a root directory of the folder structure and delete the files in the subdirectories that are listed. Any help at all with this would be great as I've been banging my head against it for hours.

  • Ludovik
Was it helpful?

Solution

In the simplest case: as your text file lines have relative paths then the batch file has to be executed from the relative folder in question.

If your text file has fully qualified paths names then it can be launched from anywhere.

OTHER TIPS

If you're trying to delete something from a certain drive, but not in like the system files, you'd have to make a completely valid path. Unless the file is already in the folder the file(s) are contained in, you would be able to do the same, but otherwise, you MIGHT have to run the file in administrator mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top