0

I would like to delete a file name from a txt list ussing a drag and drop function however i cant get my code to work

:delete
setlocal enableDelayedExpansion
set /p dnr=%1
find /v "!dnr!" document.txt > deleted.txt
pause
LabRat
  • 1,996
  • 11
  • 56
  • 91

1 Answers1

0

This will remove the file you drag and drop onto it, from the text file (presuming name and extension format). If it's full path format then change the %%~nxa to %%a.

:delete
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in ("%1") do (
set dnr=%%~nxa
find /v "!dnr!" filenames.txt >deleted.txt 
)    
for /f "skip=2 tokens=* delims=" %%x in (deleted.txt) do echo %%x >>new.txt
del deleted.txt /f /q
ren new.txt deleted.txt
Bali C
  • 30,582
  • 35
  • 123
  • 152
  • This works fine, however the deleted.txt text file has that annoying ---------- C:\FILENAMES.TXT at the begining of it is there a way to supress this or get rid of it? – LabRat Jan 02 '13 at 14:17
  • I have updated my answer to get rid of it. It's only 3 extra lines, it would be better if they had a `find` switch that would not include it though! – Bali C Jan 02 '13 at 14:30
  • actually it was onther post of yours on stack overflow http://stackoverflow.com/questions/11428692/batch-file-to-delete-first-3-lines-of-a-text-file – LabRat Jan 02 '13 at 14:47