ONTAP Discussions

Cifs share periodic file deletion script

terhand
1,360 Views

Hello, I want to periodically automatically delete the content of one of my share files.
I changed the following instruction according to myself, I applied it, but I am not getting any results.
Anyone have experience on this?

 

set folder="\\X.X.X.X\path" cd /d %folder% for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del " %%i" /s/q)

 

https://helpdeskgeek.com/help-desk/fix-scheduled-task-wont-run-bat-file/

1 ACCEPTED SOLUTION

terhand
1,308 Views

I was able to delete the network file share with periodic task with the following batch. my problem is solved, but if there are any suggestions about the method or different, I can take it.

 

@ECHO OFF

SET THEDIR=path-to-folder

Echo Deleting all files from %THEDIR%
DEL "%THEDIR%\*" /F /Q /A

Echo Deleting all folders from %THEDIR%
FOR /F "eol=| delims=" %%I in ('dir "%THEDIR%\*" /AD /B 2^>nul') do rd /Q /S "%THEDIR%\%%I"
@ECHO Folder deleted.

EXIT

View solution in original post

1 REPLY 1

terhand
1,309 Views

I was able to delete the network file share with periodic task with the following batch. my problem is solved, but if there are any suggestions about the method or different, I can take it.

 

@ECHO OFF

SET THEDIR=path-to-folder

Echo Deleting all files from %THEDIR%
DEL "%THEDIR%\*" /F /Q /A

Echo Deleting all folders from %THEDIR%
FOR /F "eol=| delims=" %%I in ('dir "%THEDIR%\*" /AD /B 2^>nul') do rd /Q /S "%THEDIR%\%%I"
@ECHO Folder deleted.

EXIT

Public