To read the files in the folder only once

Hey all,

I have a directory which contains multiple files in it.
I want to read the file only once.

i.e if There are files from 1 to 50 in the directory and in the first run the files upto 20 are processed, in the next run i don’t want to repeat those same files that is from 21 onward.
Any idea?

Thanks in Advance.

An idea is to write the filenames into a datatable. Write those to an excel. On the next run, read the excel to a datatable and then compare the filename to the datatable, if the filename is already in the datatable then it will not be processed.

2 Likes

Hey @avejr748

Thank you so much for the response!
I wanted to know if there is any dynamic method for the problem statement?

hi,
you can move file to another location/folder once you processed, so from the next run the processed files will not be available in the input location.

2 Likes

Hey @shaikmdrafi,

Thanks for the help!

Can’t move the file.
Any other approach?

Thanks

@ray_sha Besides both of the approach mentioned by @avejr748 and @shaikmdrafi you can have a copy of processed file in some temp folder and for every item and run check.
If file is already exists in temp then skip it and get the next file.

Hey @Arpit_Kesharwani,

Thanks for the help!

How exactly would you suggest?

@ray_sha create a new folder in your local project and for each file check if file is already exists in that folder if not then create a copy of processing file inside otherwise skip

hey @Arpit_Kesharwani

I have saved the processed sub folder in another folder.
Now I have to compare if the sub folders are present in the other folder as well.

How would I condition the if ?
Thanks

@ray_sha you just need to check if a file which you picked up next exists in that folder or not so your if condition would be File.exists(tempfolderpath+path.getfilename(nextdilepath))
If true then skip otherwise process the file and also make a copy into tempfolder

1 Like

Hey,
Say there are a total of 50 sub folders in the main file and in that first run 10 of which are processed.
The bot may be stopped of some reason.
Now in the second run, those 10 sub folders which were processed shouldn’t be processed again, the bot must continue from the 11th sub folder.

Hey @Arpit_Kesharwani
.exists isn’t coming up

@ray_sha you don’t need to create sub folders for each run, just one folder and copy your all processed files here in that folder only

@ray_sha sorry for the confusion it would be path.exists

so now the condition would be

path.exists(tempfolderpath+path.getfilename(nextdilepath))

Doesn’t work as well

@ray_sha

Hey,

Check this out.FileComparison.zip (2.8 MB)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.