Tag Archives


Windows Batch File to Remove Sample files

May 12, 2017 0 comments

Another Windows batch file I wrote up that will delete all folders and files with (SAMPLE) in the file or folder name.

Please note you can download the full .bat file below.

'On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")

ShowSubFolders objFSO.GetFolder("E:")

Sub ShowSubFolders(Folder)


    For Each file In Folder.Files

        Set objCurFile = objFSO.GetFile(file)

        If Instr(ucase(objCurFile.Name), UCase("sample")) Then objCurFile.Delete
        On Error Resume Next


    For Each Subfolder in Folder.SubFolders

        ShowSubFolders Subfolder


End Sub

Remove Samples Batch Files (149 downloads)

Windows Batch File to Remove Junk Files (.png, .txt, .srt, .nfo)

May 12, 2017 0 comments

Since I download a ton of different files I’m always left with a hard drive cluttered with a mess of junk files.

So I wrote up a Windows bat file that will scan a directory on my computer and remove the following junk files:

  • txt
  • jpg
  • nfo
  • png
  • gif
  • bmp
  • srt

You can easily add your own file extensions to remove.  This will also check inside of folders as well.

Here is the complete batch file code, please note you can also download this below.

DIM strExtensionsToDelete,strFolder
DIM objFSO, MaxAge, IncludeSubFolders

' ************************************************************
' Setup
' ************************************************************

' Folder to delete files
strFolder = "I:###Downloads"
' Delete files from sub-folders?
includeSubfolders = true
' A comma separated list of file extensions
' Files with extensions provided in the list below will be deleted
strExtensionsToDelete = "txt,jpg,nfo,png,gif,bmp,srt"
' Max File Age (in Days).  Files older than this will be deleted.
maxAge = 0

' ************************************************************

set objFSO = createobject("Scripting.FileSystemObject")

DeleteFiles strFolder,strExtensionsToDelete, maxAge, includeSubFolders

sub DeleteFiles(byval strDirectory,byval strExtensionsToDelete,byval maxAge,includeSubFolders)
    DIM objFolder, objSubFolder, objFile
    DIM strExt

    set objFolder = objFSO.GetFolder(strDirectory)
    for each objFile in objFolder.Files
        for each strExt in SPLIT(UCASE(strExtensionsToDelete),",")
            if RIGHT(UCASE(objFile.Path),LEN(strExt)+1) = "." & strExt then
                IF objFile.DateLastModified < (Now - MaxAge) THEN
                    exit for
                END IF
            end if
    if includeSubFolders = true then ' Recursive delete
        for each objSubFolder in objFolder.SubFolders
            DeleteFiles objSubFolder.Path,strExtensionsToDelete,maxAge, includeSubFolders
    end if
end sub

Remove Junk Files Batch (28 downloads)