What's new

Auto Delete File if Detected

reacah

Eternal Poster
Established
Joined
Oct 9, 2015
Posts
1,095
Reaction
167
Points
362
Age
34
Write a code or script that will automatically delete the specific file extension if detected
 
Sure, here's a code snippet in Python that will automatically delete all files with a specific file extension:

Python:
import os

# specify the directory path to search for files
directory = '/path/to/directory'

# specify the file extension to delete
file_extension = '.txt'

# loop through all files in the directory
for filename in os.listdir(directory):

    # check if file has the specified extension
    if filename.endswith(file_extension):
        
        # delete the file
        os.remove(os.path.join(directory, filename))

This code will search for all files in the specified directory with the .txt file extension and delete them. You can modify the directory and file_extension variables to fit your specific needs.

Note that this code will permanently delete the files, so be careful when running it.
 
Sure, here's a code snippet in Python that will automatically delete all files with a specific file extension:

Python:
import os

# specify the directory path to search for files
directory = '/path/to/directory'

# specify the file extension to delete
file_extension = '.txt'

# loop through all files in the directory
for filename in os.listdir(directory):

    # check if file has the specified extension
    if filename.endswith(file_extension):
       
        # delete the file
        os.remove(os.path.join(directory, filename))

This code will search for all files in the specified directory with the .txt file extension and delete them. You can modify the directory and file_extension variables to fit your specific needs.

Note that this code will permanently delete the files, so be careful when running it.
write a batch script that will automatically delete the multiple file extension if detected
 
write a batch script that will automatically delete the multiple file extension if detected
Sure, here's a batch script that will delete multiple file extensions if detected:

Code:
@echo off
set "extensions=.txt .docx .pdf"

for %%i in (%extensions%) do (
  del /s /q "C:\Path\To\Folder\*.%%i" >&-
)

This script will delete all files with the extensions specified in the extensions variable in the folder specified in the del command. You can modify the extensions and folder paths to fit your specific needs.

Note that this script will permanently delete the files, so be careful when running it. Also, the /s flag in the del command will search subdirectories as well, so make sure you want to delete all files with the specified extensions in all subdirectories as well.
 
Sure, here's a batch script that will delete multiple file extensions if detected:

Code:
@echo off
set "extensions=.txt .docx .pdf"

for %%i in (%extensions%) do (
  del /s /q "C:\Path\To\Folder\*.%%i" >&-
)

This script will delete all files with the extensions specified in the extensions variable in the folder specified in the del command. You can modify the extensions and folder paths to fit your specific needs.

Note that this script will permanently delete the files, so be careful when running it. Also, the /s flag in the del command will search subdirectories as well, so make sure you want to delete all files with the specified extensions in all subdirectories as well.
write a batch script that will automatically delete the multiple file extension in multiple locations if detected
 
write a batch script that will automatically delete the multiple file extension in multiple locations if detected
Sure, here's a batch script that will delete multiple file extensions if detected in multiple locations:

Code:
@echo off
set "extensions=.txt .docx .pdf"
set "locations=Location1 Location2 Location3"

for %%j in (%locations%) do (
    cd "%%j"
    for %%i in (%extensions%) do (
        del /s /q "%%j\*.%%i" >&-
    )
)

This script will delete all files with the extensions specified in the extensions variable in each folder specified in the locations variable. You can modify the extensions and folder paths to fit your specific needs.

Note that this script will permanently delete the files, so be careful when running it. Also, the /s flag in the del command will search subdirectories as well, so make sure you want to delete all files with the specified extensions in all subdirectories as well.
 
Sure, here's a batch script that will delete multiple file extensions if detected in multiple locations:

Code:
@echo off
set "extensions=.txt .docx .pdf"
set "locations=Location1 Location2 Location3"

for %%j in (%locations%) do (
    cd "%%j"
    for %%i in (%extensions%) do (
        del /s /q "%%j\*.%%i" >&-
    )
)

This script will delete all files with the extensions specified in the extensions variable in each folder specified in the locations variable. You can modify the extensions and folder paths to fit your specific needs.

Note that this script will permanently delete the files, so be careful when running it. Also, the /s flag in the del command will search subdirectories as well, so make sure you want to delete all files with the specified extensions in all subdirectories as well.
write a batch script that will automatically delete the multiple file extension in multiple locations if detected for windows operating system
 
write a batch script that will automatically delete the multiple file extension in multiple locations if detected for windows operating system
Sure, here's a batch script that will delete multiple file extensions if detected in multiple locations for Windows operating system:

Code:
@echo off
set "extensions=.txt .docx .pdf"
set "locations=C:\Location1 D:\Location2 E:\Location3"

for %%j in (%locations%) do (
    cd "%%j"
    for %%i in (%extensions%) do (
        del /s /q "%%j\*.%%i" >&-
    )
)

This batch script will delete all files with the extensions specified in the extensions variable in each folder specified in the locations variable. You can modify the extensions and folder paths to fit your specific needs.

Note that this script will permanently delete the files, so be careful when running it. Also, the /s flag in the del command will search subdirectories as well, so make sure you want to delete all files with the specified extensions in all subdirectories as well.
 
Sure, here's a batch script that will delete multiple file extensions if detected in multiple locations for Windows operating system:

Code:
@echo off
set "extensions=.txt .docx .pdf"
set "locations=C:\Location1 D:\Location2 E:\Location3"

for %%j in (%locations%) do (
    cd "%%j"
    for %%i in (%extensions%) do (
        del /s /q "%%j\*.%%i" >&-
    )
)

This batch script will delete all files with the extensions specified in the extensions variable in each folder specified in the locations variable. You can modify the extensions and folder paths to fit your specific needs.

Note that this script will permanently delete the files, so be careful when running it. Also, the /s flag in the del command will search subdirectories as well, so make sure you want to delete all files with the specified extensions in all subdirectories as well.
this code does not work
 
this code does not work
I apologize for the confusion, here is an updated version of the batch script that should work:

Code:
@echo off
set "extensions=.txt .docx .pdf"
set "locations=C:\Location1 D:\Location2 E:\Location3"

for %%j in (%locations%) do (
    pushd "%%j"
    for %%i in (%extensions%) do (
        del /s /q "*%%i"
    )
    popd
)

This batch script will delete all files with the extensions specified in the extensions variable in each folder specified in the locations variable. You can modify the extensions and folder paths to fit your specific needs.

Note that this script will permanently delete the files, so be careful when running it. Also, the /s flag in the del command will search subdirectories as well, so make sure you want to delete all files with the specified extensions in all subdirectories as well.
 
I apologize for the confusion, here is an updated version of the batch script that should work:

Code:
@echo off
set "extensions=.txt .docx .pdf"
set "locations=C:\Location1 D:\Location2 E:\Location3"

for %%j in (%locations%) do (
    pushd "%%j"
    for %%i in (%extensions%) do (
        del /s /q "*%%i"
    )
    popd
)

This batch script will delete all files with the extensions specified in the extensions variable in each folder specified in the locations variable. You can modify the extensions and folder paths to fit your specific needs.

Note that this script will permanently delete the files, so be careful when running it. Also, the /s flag in the del command will search subdirectories as well, so make sure you want to delete all files with the specified extensions in all subdirectories as well.
this code works
 

Similar threads

Back
Top