Page 1 of 1

How to copy the latest file in a folder

Posted: Tue Jan 06, 2009 5:53 pm
by robotask846
How to copy  the latest file in a folder:
Do you have a macro that can monitor a particular folder and move only the latest file in that folder ( modified or created last ) to another pre-determined folder.
 
Thank you.
 

How to copy the latest file in a folder

Posted: Tue Jan 06, 2009 11:48 pm
by Oleg
See the example "[DEMO] Find the latest/newest modified file in a folder."
This task determines latest file in specified folder.
Next, you can copy this file or do some else.

Of course, you may copy and change this task for your purposes.

How to copy the latest file in a folder

Posted: Wed Jan 07, 2009 12:57 pm
by robotask846
Hi Oleg,
I had already tried that.  I do not know how to modify this macro to achieve this purpose. Could you please help me if it is not much trouble. 
I need to find the latest file in a folder and move it to a diferent folder.
Thank you.
 

How to copy the latest file in a folder

Posted: Thu Jan 08, 2009 11:25 pm
by Oleg
See example below.
Pay attention to steps:
step #9. I turned off the "Without full path" parameter
step #19 Copy/Move file (added step)

;*****************************
;* RoboTask Task file       
;* Do not edit in text editor!
;*****************************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|1214054504
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task752"
Hide=INTEGER|0
ID=INTEGER|729685853
LogOnAsUser=INTEGER|1
Name=STRING|"[DEMO] Find the latest/newest modified file in a folder and copy it."
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action15=FOLDER
Action16=FOLDER
Action17=FOLDER
Action18=FOLDER
Action19=FOLDER
Action2=FOLDER
Action20=FOLDER
Action21=FOLDER
Action22=FOLDER
Action23=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""This Demo finds the latest file in a specified folder."""
Params=FOLDER

[Actions\Action1\Params]
icon=STRING|"1"
msg0=STRING|"This Demo finds the latest file in a specified folder."
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

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

[Actions\Action10\Params]
message=STRING|"Current DateTime {CURRENT_DATETIME}"
type=STRING|"0"

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

[Actions\Action11\Params]
message=STRING|"Latest DateTime {LATEST_DATETIME}"
type=STRING|"0"

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

[Actions\Action12\Params]
case=STRING|"0"
operator=STRING|"3"
type=STRING|"2"
value1=STRING|"{CURRENT_DATETIME}"
value2=STRING|"{LATEST_DATETIME}"

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

[Actions\Action13\Params]
message=STRING|"CURRENT_DATETIME {CURRENT_DATETIME} > LATEST_DATETIME {LATEST_DATETIME}"
type=STRING|"0"

[Actions\Action14]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""LATEST_FILENAME"" with value ""{CURRENT_FILENAME}"""
Params=FOLDER

[Actions\Action14\Params]
expand=STRING|"1"
varname=STRING|"LATEST_FILENAME"
varvalue=STRING|"{CURRENT_FILENAME}"

[Actions\Action15]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""LATEST_DATETIME"" with value ""{CURRENT_DATETIME}"""
Params=FOLDER

[Actions\Action15\Params]
expand=STRING|"1"
varname=STRING|"LATEST_DATETIME"
varvalue=STRING|"{CURRENT_DATETIME}"

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

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

[Actions\Action18]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Folder: {Current_Folder}"""
Params=FOLDER

[Actions\Action18\Params]
icon=STRING|"1"
msg0=STRING|"Folder: {Current_Folder}"
msg1=STRING|"Latest file: {LATEST_FILENAME}"
msg2=STRING|"Modified: {LATEST_DATETIME}"
msg4=STRING|"Press OK to copy it to ""c:\destination"" folder"
msgcount=STRING|"5"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action19]
ActionID=STRING|"A_FILE_COPY"
Enabled=INTEGER|-1
Name=STRING|"Copy/Move File"
Params=FOLDER

[Actions\Action19\Params]
destdir=STRING|"C:\destination"
f_count=STRING|"1"
file0=STRING|"{LATEST_FILENAME}"
ifexists=STRING|"1"
move=STRING|"0"
subdir=STRING|"0"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create variable ""LATEST_FILENAME"" with value ""Not Found"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varname=STRING|"LATEST_FILENAME"
varvalue=STRING|"Not Found"

[Actions\Action20]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""CURRENT_FOLDER"""
Params=FOLDER

[Actions\Action20\Params]
varname=STRING|"CURRENT_FOLDER"

[Actions\Action21]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""CURRENT_FILE"""
Params=FOLDER

[Actions\Action21\Params]
varname=STRING|"CURRENT_FILE"

[Actions\Action22]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""LATEST_DATETIME"""
Params=FOLDER

[Actions\Action22\Params]
varname=STRING|"LATEST_DATETIME"

[Actions\Action23]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""LATEST_FILENAME"""
Params=FOLDER

[Actions\Action23\Params]
varname=STRING|"LATEST_FILENAME"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create variable ""LATEST_DATETIME"" with value ""0"""
Params=FOLDER

[Actions\Action3\Params]
expand=STRING|"0"
varname=STRING|"LATEST_DATETIME"
varvalue=STRING|"0"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_BROWSEFOLDERS"
Enabled=INTEGER|-1
Name=STRING|"Browse for Folders"
Params=FOLDER

[Actions\Action4\Params]
caption=STRING|"Select Folder"
default=STRING|"None"
filter=STRING|"Text files|*.txt|All files|*.*|"
folder=STRING|"{TempDir}"
variable=STRING|"CURRENT_FOLDER"

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

[Actions\Action5\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"0"
value1=STRING|"{Current_Folder}"
value2=STRING|"None"

[Actions\Action6]
ActionID=STRING|"A_TASKS_STOP"
Enabled=INTEGER|-1
Name=STRING|"Stop Task ""Find the latest/newest modified file in a folder."""
Params=FOLDER

[Actions\Action6\Params]
taskid=STRING|"417887772"

[Actions\Action7]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|0
Name=STRING|"Set variable ""CURRENT_FOLDER"" with value ""{TempDir}"""
Params=FOLDER

[Actions\Action7\Params]
expand=STRING|"1"
varname=STRING|"CURRENT_FOLDER"
varvalue=STRING|"{TempDir}"

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

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

[Actions\Action9\Params]
createmode=STRING|"1"
date1=STRING|"20040520"
date2=STRING|"20040520"
destvar=STRING|"CURRENT_FILENAME"
DuringDays=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"{Current_Folder}\*.*"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
subdirs=STRING|"1"
timesize=STRING|"1"
timevar=STRING|"CURRENT_DATETIME"
WithoutPath=STRING|"0"

How to copy the latest file in a folder

Posted: Sat Jan 10, 2009 7:05 pm
by robotask846
Hi Oleg,
Thank you so much for your help.
Robotask is the single greatest applications I have found after extensive research.   I am so happy with it.  it is literally saving me time.  It is great.  The tech support is second to none.  
Just to thank you Oleg.