How to delete a file with the same name from files in multiple folders?

Discuss RoboTask here
Post Reply
anthonyystwarty
Posts: 47
Joined: Fri Dec 30, 2022 2:43 am

How to delete a file with the same name from files in multiple folders?

Post by anthonyystwarty »

Hello, have a nice day!
I already looked and didn't find How to delete a file with the same name, ex test.mp3 which is on the local disk c:?
Can you help me?
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How to delete a file with the same name from files in multiple folders?

Post by Oleg »

... delete a file with the same name, ex test.mp3 which is on the local disk ...
you can use File Loop to find files by name or mask in folder and sybfolders

Look at my example below. It seaches file list.txt in subfolders starting from folder D:\incoming\test\

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task19"
Hide=INTEGER|0
ID=INTEGER|1222396254
LogOnAsUser=INTEGER|1
Name=STRING|"Find copies in a folder and subfolders"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""startfolder"" with value ""D:\incoming\test"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"startfolder"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"startfolder"
varvalue=STRING|"D:\incoming\test"

[Actions\Action10]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action11]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""SearchFile"" with value ""list.txt"""
Params=FOLDER

[Actions\Action2\Params]
_rt_variables_produced=STRING|"SearchFile"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"SearchFile"
varvalue=STRING|"list.txt"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""firstFile"" with value ""true"""
Params=FOLDER

[Actions\Action3\Params]
_rt_variables_produced=STRING|"firstFile"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"firstFile"
varvalue=STRING|"true"

[Actions\Action4]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER

[Actions\Action4\Params]
_rt_variables_produced=STRING|"filename"
createmode=STRING|"1"
date1=STRING|"20231104"
date2=STRING|"20231104"
destvar=STRING|"filename"
DuringDays=STRING|"1"
DuringHours=STRING|"1"
DuringMinutes=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"{startfolder}\{SearchFile}"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderHours=STRING|"1"
OlderMinutes=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
sort=STRING|"1"
sortby=STRING|"3"
sortorder=STRING|"0"
subdirs=STRING|"1"
timesize=STRING|"0"
WithoutPath=STRING|"0"

[Actions\Action5]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action5\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{firstFile}"

[Actions\Action6]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action6\Params]
message=STRING|"first file (keep it) {filename} "
type=STRING|"3"

[Actions\Action7]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""firstFile"" with value ""false"""
Params=FOLDER

[Actions\Action7\Params]
_rt_variables_produced=STRING|"firstFile"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"firstFile"
varvalue=STRING|"false"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action9]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action9\Params]
message=STRING|"The copy (remove it) {filename} "
type=STRING|"3"

Oleg Yershov
anthonyystwarty
Posts: 47
Joined: Fri Dec 30, 2022 2:43 am

Re: How to delete a file with the same name from files in multiple folders?

Post by anthonyystwarty »

Hello, sorry for the delay Oleg. With your task I managed to find the list.txt, but how do I delete the list.txt from the folders? Thank you friend
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How to delete a file with the same name from files in multiple folders?

Post by Oleg »

Look at the new task. The step #10 (Delete file) removes extra copies of the file

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task19"
Hide=INTEGER|0
ID=INTEGER|1222396254
LogOnAsUser=INTEGER|1
Name=STRING|"Find copies in a folder and subfolders (with delete files)"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""startfolder"" with value ""D:\incoming\test"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"startfolder"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"startfolder"
varvalue=STRING|"D:\incoming\test"

[Actions\Action10]
ActionID=STRING|"A_FILE_DELETE"
Enabled=INTEGER|-1
Name=STRING|"Delete File"
Params=FOLDER

[Actions\Action10\Params]
Count=STRING|"1"
deletedirs=STRING|"0"
deletereadonly=STRING|"0"
file0=STRING|"{filename}"
hidden=STRING|"1"
subdir=STRING|"0"
system=STRING|"1"
ToRecycleBin=STRING|"0"

[Actions\Action11]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action12]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""SearchFile"" with value ""list.txt"""
Params=FOLDER

[Actions\Action2\Params]
_rt_variables_produced=STRING|"SearchFile"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"SearchFile"
varvalue=STRING|"list.txt"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""firstFile"" with value ""true"""
Params=FOLDER

[Actions\Action3\Params]
_rt_variables_produced=STRING|"firstFile"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"firstFile"
varvalue=STRING|"true"

[Actions\Action4]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER

[Actions\Action4\Params]
_rt_variables_produced=STRING|"filename"
createmode=STRING|"1"
date1=STRING|"20231104"
date2=STRING|"20231104"
destvar=STRING|"filename"
DuringDays=STRING|"1"
DuringHours=STRING|"1"
DuringMinutes=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"{startfolder}\{SearchFile}"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderHours=STRING|"1"
OlderMinutes=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
sort=STRING|"1"
sortby=STRING|"3"
sortorder=STRING|"0"
subdirs=STRING|"1"
timesize=STRING|"0"
WithoutPath=STRING|"0"

[Actions\Action5]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action5\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{firstFile}"

[Actions\Action6]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action6\Params]
message=STRING|"first file (keep it) {filename} "
type=STRING|"3"

[Actions\Action7]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""firstFile"" with value ""false"""
Params=FOLDER

[Actions\Action7\Params]
_rt_variables_produced=STRING|"firstFile"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"firstFile"
varvalue=STRING|"false"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action9]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action9\Params]
message=STRING|"The copy (remove it) {filename} "
type=STRING|"3"

Oleg Yershov
anthonyystwarty
Posts: 47
Joined: Fri Dec 30, 2022 2:43 am

Re: How to delete a file with the same name from files in multiple folders?

Post by anthonyystwarty »

To delete all list.txt in the folders, is this the command? I am unable.
Attachments
2023-11-17_18-16-47.jpg
2023-11-17_18-16-47.jpg (140.5 KiB) Viewed 29739 times
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How to delete a file with the same name from files in multiple folders?

Post by Oleg »

If I understood correctly you want to keep one file and delete rest files with same file name (as you wrote at the beginning of the topic). Correct?
In this case you should delete files sequentially as in my task and keep 1-st file

If you write delete file by mask (list*.txt) - the action removes all files

If you want to delete all files by mask you don't need such complex algorithm, just use the action Delete file with Process subfolders option
The mask example: d:\incoming\list*.txt
In this case the action deletes all files list*.txt in folder d:\incoming and all subfolders
Oleg Yershov
anthonyystwarty
Posts: 47
Joined: Fri Dec 30, 2022 2:43 am

Re: How to delete a file with the same name from files in multiple folders?

Post by anthonyystwarty »

Now I got it friend, you are kind and very intelligent. Thank you very much.
Post Reply