Delete file/files from folder

Hi, I looked for this but couldn’t find it.

can you do it so I can give path and 1, single files and 2, multiple file so:

c:\path\folder\

file 1 text.txt
file 2 demo.exe

Cheers.

Hi @dittoit

We will analyze and update the script request shortly.

Thank you.

hi @dittoit

We have completed the script to delete file/files from the folder.

Note:

  1. Provide correct path of the folder where the file is stored.

  2. Provide the name of the files with exact file format.

Link: https://scripts.comodo.com/backend/web/topic/update/remove-file-from-folder

Thank you

Hi can’t access
403 Forbidden


nginx

Hi @dittoit

Sorry for your inconvenience.Please refer this script for delete files from a folder,

https://scripts.comodo.com/frontend/web/topic/remove-file-from-folder

Thank you.

Hi,

it didn’t delete the file:

I # the 2nd file as it failed with it included.

Can we not have Files to be deleted in “file.txt,file2.txt,etc.exe” in a single line

as if we have lotsthis script as it is wont work

import os
f1=‘delete.txt’ # provide the file name with its format
#f2=‘nomachine_6.0.78_1.exe’ # provide the file name with its format
dirPath = r"D:\Desktop\Temp Invoice" #provide the path where the file is created
#Remember to provide the back slash as valid format
fileList = os.listdir(dirPath)
for f in fileList:
if f==f1:
os.remove(dirPath+“"+f)
print f+” "+“file removed”

if f==f2:

os.remove(dirPath+""+f)

print f+" "+ “file removed”

Cheers James.

Hi @dittoit

We will modify the script and update you shortly.

Thank you.

Hi @dittoit

Refer this script to delete file or files specified in a folder.

https://scripts.comodo.com/frontend/web/topic/remove-file-from-folder

Thank you.

Hi, yep that worked. 2 things, ITS CASE sensitive, and can we have “no files removed” if it doesn’t as you still get a success even though it doesn’t remove any files.

great :slight_smile:

Looks like it wont remove files that need Administrator permissions, or are set as read only?

How can we get around this?

Have you tried to run the script as a system user, @dittoit ? A function to acquire the proper set of permissions on the file can be added to the script.

For a read-only file, this will require changes on the script so that if the file to be deleted is read-only, file attributes need to be adjusted accordingly. We will let @Preethi decide on the changes to be made on the script.

Yes as a system user the script runs fine. But it won’t delete the files I need to that are read only and hidden.

Hi @dittoit , @Rick_C

Refer the following script to delete file or files specified in a folder.

https://scripts.comodo.com/frontend/web/topic/remove-files-from-folder

Note:

  • It will delete the files which it has been specified in Hidden also
  • Run as System User
Thank you

Please advise: it didn’t remove the files? what has it tried to remove? why are is the folder c:\Windows
this is what I filled in the script:

dirPath = r"C:\GRBData\local{5066F8BB-218C-4B6A-B931-2D63979D1FE2}\Media{79DB1E4F-D843-40AB-B896-E4B654FD2CB9}\ServerFolders\SageAccountsData\Company.000\Accdata"# provide the file path
f1=“natalie.skc,vanessa.fic”# provide the file name along with its format

Time
Status
Additional information
2018/03/01 12:48:21 PM
Finished success
Access denied - C:\Windows\system32\0409\scregedit.ini

Access denied - C:\Windows\system32\AdvancedInstallers\cmiadapter.dll

Access denied - C:\Windows\system32\AdvancedInstallers\cmiv2.dll

Access denied - C:\Windows\system32\ar-SA\cdosys.dll.mui

Access denied - C:\Windows\system32\ar-SA\comctl32.dll.mui

Access denied - C:\Windows\system32\ar-SA\comdlg32.dll.mui

Access denied - C:\Windows\system32\ar-SA\fms.dll.mui

Access denied - C:\Windows\system32\ar-SA\mlang.dll.mui

Access denied - C:\Windows\system32\ar-SA\msimsg.dll.mui

Access denied - C:\Windows\system32\ar-SA\msprivs.dll.mui

Access denied - C:\Windows\system32\ar-SA\windows.ui.xaml.dll.mui

Access denied - C:\Windows\system32\bg-BG\comctl32.dll.mui

Access denied - C:\Windows\system32\bg-BG\comdlg32.dll.mui

Access denied - C:\Windows\system32\bg-BG\fms.dll.mui

Access denied - C:\Windows\system32\bg-BG\mlang.dll.mui

Access denied - C:\Windows\system32\bg-BG\msimsg.dll.mui

Access denied - C:\Windows\system32\bg-BG\windows.ui.xaml.dll.mui

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Adobe-Flash-For-Windows-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-PowerShell-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-PowerShell-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-TRLParser-Package-ds~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-TRLParser-Package-ds~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-WebServices-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-WebServices-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-CertificateServices-PKIClient-PSH-Cmdlets-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-CertificateServices-PKIClient-PSH-Cmdlets-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Clustering-Vmclusex-package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Clustering-Vmclusex-package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Common-Drivers-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Guest-Integration-Drivers-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-Clients-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-Clients-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-PowerShell-Package-net~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-PowerShell-Package-net~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-PowerShell-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-PowerShell-Package~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Package-ds~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Package-minkernel~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Package-net~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Package-net~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Package-redist~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Package-termsrv~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Package-termsrv~31bf3856ad364e35~amd64~~6.3.9600.16384.cat

Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Server-Drivers-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat

Any ideas guys ??

Hi @dittoit

We cant able to delete the OS related files from the system.In such case, it will be shown under as Access Denied and manually itself we can’t able to delete such files from the system.

Thank you.

You completely missed the point !! Why did the script try to remove them !! It shouldn’t be going no where near these files !!

I never stipulated these files to be removed.

please check the script again.

it’s wrong if it is trying to delete these system files.

I want to delete files from inside this path

C:\GRBData\local{5066F8BB-218C-4B6A-B931-2D63979D1FE2}\Media{79DB1E4F-D843-40AB-B896-E4B654FD2CB9}\ServerFolders\SageAccountsData\Compa ny.000\Accdata

Hi @dittoit
We will make sure that the script developers ( @Preethi , @Vignesh , @pradeep , and others) address the observation you shared with us.

Hi @Rick_C, @dittoit,

kindly run the script as System User.The script works fine in our environment. Please provide a feedback once again after trying the script.

Thank you

Ran as system user:

see below, and attached JSON.

Device Name Started At Started By Launch Type Executed By Finished At Status Last Status Update Details
2012R2
		</td>
		<td>2018/03/05 11:54:35 AM</td>
		<td>  			<a href="https://dittoit-msp.cmdm.comodo.com/user/account/app#/user/1/info">admin</a>

		</td>
		<td>Run Over</td>
		<td>LocalSystem User</td>
		<td>2018/03/05 11:54:42 AM</td>
		<td>Finished success</td>
		<td>2018/03/05 11:54:42 AM</td>
		<td>Details</td>
	</tr>

Access denied - C:\Windows\system32\0409\scregedit.ini
Access denied - C:\Windows\system32\AdvancedInstallers\cmiadapter.dll
Access denied - C:\Windows\system32\AdvancedInstallers\cmiv2.dll
Access denied - C:\Windows\system32\ar-SA\cdosys.dll.mui
Access denied - C:\Windows\system32\ar-SA\comctl32.dll.mui
Access denied - C:\Windows\system32\ar-SA\comdlg32.dll.mui
Access denied - C:\Windows\system32\ar-SA\fms.dll.mui
Access denied - C:\Windows\system32\ar-SA\mlang.dll.mui
Access denied - C:\Windows\system32\ar-SA\msimsg.dll.mui
Access denied - C:\Windows\system32\ar-SA\msprivs.dll.mui
Access denied - C:\Windows\system32\ar-SA\windows.ui.xaml.dll.mui
Access denied - C:\Windows\system32\bg-BG\comctl32.dll.mui
Access denied - C:\Windows\system32\bg-BG\comdlg32.dll.mui
Access denied - C:\Windows\system32\bg-BG\fms.dll.mui
Access denied - C:\Windows\system32\bg-BG\mlang.dll.mui
Access denied - C:\Windows\system32\bg-BG\msimsg.dll.mui
Access denied - C:\Windows\system32\bg-BG\windows.ui.xaml.dll.mui
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Adobe-Flash-For-Windows-Package~31bf3856ad364e35~amd646.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-PowerShell-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-PowerShell-Package~31bf3856ad364e35~amd64
6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-TRLParser-Package-ds~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-TRLParser-Package-ds~31bf3856ad364e35~amd646.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-WebServices-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-ActiveDirectory-WebServices-Package~31bf3856ad364e35~amd64
6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-CertificateServices-PKIClient-PSH-Cmdlets-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-CertificateServices-PKIClient-PSH-Cmdlets-Package~31bf3856ad364e35~amd646.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Clustering-Vmclusex-package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Clustering-Vmclusex-package~31bf3856ad364e35~amd64
6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Common-Drivers-Package~31bf3856ad364e35~amd646.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Guest-Integration-Drivers-Package~31bf3856ad364e35~amd64
6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-Clients-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-Clients-Package~31bf3856ad364e35~amd646.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-PowerShell-Package-net~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-PowerShell-Package-net~31bf3856ad364e35~amd64
6.3.9600.16384.cat
Access denied - C:\Windows\system32\catroot{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft-Hyper-V-Management-PowerShell-Package~31bf3856ad364e35~amd64~en-US~6.3.9600.16384.cat
ETC !!!

20180305-Delete-Files.json (1.25 KB)