Script package to delete files

I have a script package as follows.

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

The above code deletes all “.txt” and “.tsv” files from all folders except the TEST 100% folder. To delete files from TEST 100% I get an error message like The Path could not be found . I think the% symbol in the folder name is creating a problem. Can someone help me solve the problem and delete the files from the TEST 100% folder TEST 100% ?

+67
batch-file
Dec 07 '12 at 13:30
source share
5 answers

You need to avoid% with another ...

 del "D:\TEST\TEST 100%%\Archive*.TXT" 
+79
Dec 07
source share
— -

Let's say you saved your software on your desktop.
if you want to delete the entire folder, such as the uninstaller, you can use it.

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

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

Make sure you delete the correct folder. Cause This does not have a Yes / No option.

+7
May 29 '14 at 19:12
source share

There are several ways to do things in batch mode, so if you avoid the double percentage of %% , it doesn’t work for you, you can try something like this:

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

How it works:

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

cd /d "path of folder" changes the current directory the batch will look at. keep quotes and change the path to the folder that you always wanted.

del "file name/ or *.txt etc..." will delete the file in the current directory the package is looking at, just don’t add the directory path in front of the file name and just don’t use the full file name or to delete several files with the same extension using *.txt or any other extension you need.

cd /d "%olddir%" takes the variable stored with your old path and returns to the directory in which you ran the package, it doesn’t matter if you do not want the package to return to the previous directory path, and as indicated above, the variable name can be changed to whatever you wish by changing set olddir=%CD% line .

+4
Oct 18
source share

Note that the files you need to delete have the extension txt and are located in the location D:\My Folder , then you can use the code below in the bat file.

 cd "D:\My Folder" DEL *.txt 
+1
Sep 03 '16 at 15:36
source share

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

Hope this solves your problem.

-7
Nov 07 '13 at 6:59
source share



All Articles