Batch script to delete files

前端 未结 5 840
迷失自我
迷失自我 2020-12-24 04:16

I have a batch script as follows.

D:
del \"D:\\TEST\\TEST1\\Archive\\*.TSV\" 
del \"D:\\TEST\\TEST1\\Archive\\*.TXT\"
del \"D:\\TEST\\TEST2\\Archive\\*.TSV\"         


        
相关标签:
5条回答
  • 2020-12-24 04:46

    Consider that the files you need to delete have an extension txt and is located in the location D:\My Folder, then you could use the below code inside the bat file.

    cd "D:\My Folder"
    DEL *.txt 
    
    0 讨论(0)
  • You need to escape the % with another...

    del "D:\TEST\TEST 100%%\Archive*.TXT"
    
    0 讨论(0)
  • 2020-12-24 04:53

    There's multiple ways of doing things in batch, so if escaping with a double percent %% isn't working for you, then you could try something like this:

    set olddir=%CD%
    cd /d "path of folder"
    del "file name/ or *.txt etc..."
    cd /d "%olddir%"
    

    How this works:

    set olddir=%CD% sets the variable "olddir" or any other variable name you like to the directory your batch file was launched from.

    cd /d "path of folder" changes the current directory the batch will be looking at. keep the quotations and change path of folder to which ever path you aiming for.

    del "file name/ or *.txt etc..." will delete the file in the current directory your batch is looking at, just don't add a directory path before the file name and just have the full file name or, to delete multiple files with the same extension with *.txt or whatever extension you need.

    cd /d "%olddir%" takes the variable saved with your old path and goes back to the directory you started the batch with, its not important if you don't want the batch going back to its previous directory path, and like stated before the variable name can be changed to whatever you wish by changing the set olddir=%CD% line.

    0 讨论(0)
  • 2020-12-24 04:57

    in batch code your path should not contain any Space so pls change your folder name from "TEST 100%" to "TEST_100%" and your new code will be del "D:\TEST\TEST_100%\Archive*.TXT"

    hope this will resolve your problem

    0 讨论(0)
  • 2020-12-24 05:02

    Lets say you saved your software onto your desktop.
    if you want to remove an entire folder like an uninstaller program you could use this.

    cd C:\Users\User\Detsktop\
    rd /s /q SOFTWARE
    

    this will delete the entire folder called software and all of its files and subfolders

    Make Sure You Delete The Correct Folder Cause This Does Not Have A Yes / No Option

    0 讨论(0)
提交回复
热议问题