1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Delete Files While Keeping The Directory Listing

Discussion in 'T&T - Scripting' started by nchernoff, Jun 5, 2008.

  1. nchernoff

    nchernoff Administrator
    Staff Member

    Joined:
    May 16, 2008
    Messages:
    42
    Likes Received:
    2
    Migrated From JP Software Wiki

    kill_vid.btm notates a file deletion by leaving a zero-length file with a similar name. The "vid" refers to "video" but it can be used for any type of file. This works by adding a new file and then deleting the existing file. Instead of deleting the file, by modifying the final line it could simply be moved, e.g., from the local machine to a server or from a server to an external backup.

    Purpose

    Many people download a large number of audio, video or image files but don't want to keep every file downloaded. If you simply delete an unwanted file, how will you know in the future that you already viewed it, so you won't download it again?

    kill_vid.btm deletes the file but in its place leaves a zero-length file that begins with z{space} and adds a .txt extension to the original name.

    So, for instance, it would replace "Mayfield HS Prom.wmv" with "z Mayfield HS Prom.wmv.txt"

    Coding notes
    • This version works with V Communications' PowerDesk Pro, a Windows Explorer replacement with a customizable Launchbar--you drag-n-drop to the Launchbar icon, which runs this batch file.
    • PowerDesk Pro passes the Windows short filename version of the full path for the selected file in the variable %1 to the application being launched. So this file starts by determining the long name of the full path.
    • The code in this program is useful for routines that manipulate file names.
    • The reason for adding z{space} at the beginning is so it will move to the bottom of an alphabetical listing.
    • The reason for adding a .txt extension is that if you simply replace the existing file with a zero-length file Windows will think it is the original file type, e.g., a Windows Media .wmv file and if you accidentally double-click on it Windows will launch the program for that type and then tell you the file is corrupt. If you launch a zero-length .txt file Windows will simply open notepad.exe.
    • Instead of adding .txt you could create a new "deleted file" extension such as .delf and associate that extension with notepad.exe. That way when you want to search for real .txt text files, files created with this utility won't show up.

    Batch file code

    Code:
    :  KILL_VID.BTM
    :  By Joseph "Rick" Reinckens
    
    :  Creates a zero-length text file named z{space}{filename}.txt
    :  Then deletes the original file.
    :  This is for crummy downloaded videos (or other files) so I'll
    :  know the video was downloaded and seen.
    :
    :  *** IMPORTANT *** If the calling program does not pass the
    :  path, USING THIS PROGRAM CAN CAUSE UNFORESEEABLE PROBLEMS
    :  because the file name passed may not be in the active directory
    :  that 4NT sees.
    
    @echo off
    if "%1"="" exit
    
    :  For testing--You need to determine whether the calling program
    :  passes the complete path, not just the file name, and whether
    :  it passes the short or long name. If you don't know, remove
    :  the REM from the following lines
    :
    REM echo %1
    REM pause
    REM exit
    
    :  Short filename is passed as a parameter -- get long file name
    set fullname=%@lfn[%1]
    
    :  Extract filename only, since we'll change it
    set fileonly=%@filename[%fullname]
    
    :  Get path so we don't accidentally change something else.
    set pathonly=%@path[%fullname]
    
    :  Add a prefix and a .txt suffix to original filename.
    :  z{space} is just to force it to the bottom alphabetically
    set newfile=z %fileonly.txt
    
    :  Put it all in quotes in case there are spaces.
    set newfile=%@quote[%pathonly%%newfile]
    
    :  Create a zero-length file with the new name
    copy nul %newfile
    
    :  Delete the original file
    del "%fullname"


    Contributed by Rick Reinckens
     

Share This Page