How can you check if there is a new file in a folder?

uiautomation

#1

How can you check if there is a new file in a folder? I’ve checked the solution here, but it has to have a specific file name.

I’m trying to watch a folder so that when there is a new file the file is picked up and an action is done with this file. Otherwise it keeps checking.

Also, if there are two files, the older file is picked up

What commands I need to use to achieve this?


#2

hi @selrac

You can do 2 things here:

  1. After processing files move that file to another folder i.e. processed kind of.
  2. After processing append kind of timestamp or some string with filename like processed or not?.
  3. You can maintain the status with filename in an excel and check first their this name file has been processed or not.
  4. In forum i have posted a solution to check file creation dates and other properties so on the basis of that also you can identify.

for further assistence revisit some already posted posts here on the forum :slight_smile:

Regards…!!
Aksh


#3

Thanks Aksh1yadav,
The problem I have is with the first step. How do I check if the is a file in the folder?


#4

Small input - this one I wouldn’t recommend, especially for larger processes - it scales very poorly and becomes a pain if multiple robots are involved.

Points 1/2 are very good (you can add an intermediate Processing folder in between for clarity), since it’s very easy for humans to see what’s going on without shuffling through logs for processing info.

Regards.


#5

You can get all files within a folder by using:

Directory.GetFiles(FOLDER_PATH,".",SearchOption.AllDirectories)

and Loop through it having an argument String and in loop add your file processing code and also move that file into different folder.

Regards…!!
Aksh


#6

I don’t seem to have Directory.GetFiles. If I search for activities I only see ‘Create Directory’


#7

If you know the filename, try PathExists and select file in the option.


#8

I don’t know the filename. This is the problem. The files are copied to this folder with different filenames


#9

Can you try the below?


#10

It’s a static method call. Put it on the right hand side of an assign and on the left side put a variable of type List(Of String).


#11

WatchFolder2.xaml (9.6 KB)

I seem to be having some errors. I’m attaching xaml


#12

Check now

WatchFolder2.xaml (9.4 KB)


#13

Thanks. That works!!


#14

Vvaidya,

Can I ask you, what did you do to make it work?


#15

I made some changes to variable data types.


#16

I see. This is what I couldn’t figure out. Thanks