Page 1 of 1
How to delete a file with the same name from files in multiple folders?
Posted: Sat Nov 04, 2023 5:24 am
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?
Re: How to delete a file with the same name from files in multiple folders?
Posted: Sat Nov 04, 2023 8:30 am
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"
Re: How to delete a file with the same name from files in multiple folders?
Posted: Fri Nov 17, 2023 5:06 am
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
Re: How to delete a file with the same name from files in multiple folders?
Posted: Fri Nov 17, 2023 8:24 am
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"
Re: How to delete a file with the same name from files in multiple folders?
Posted: Fri Nov 17, 2023 10:18 pm
by anthonyystwarty
To delete all list.txt in the folders, is this the command? I am unable.
Re: How to delete a file with the same name from files in multiple folders?
Posted: Sat Nov 18, 2023 9:32 am
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
Re: How to delete a file with the same name from files in multiple folders?
Posted: Sun Nov 19, 2023 9:35 pm
by anthonyystwarty
Now I got it friend, you are kind and very intelligent. Thank you very much.