@ZachT124 This depends on a couple things really. You really need to know where the file is going to be able to wait for anything. If you can determine the location (by default it is the user's downloads folder, so you can get that by using the System.Environment.GetFolderPath method and combining that with the Downloads directory. Once you know that, you can use a FileSystemWatcher component or you can iterate over the directory until a new file is created. If you know the name of the file, then this is easy (just check to see if the file exists using the FileUtils. If the name is dynamic, then you might need to get a list of the files and iterate over that checking for the most recent one.
Posted: 1 year ago
Posted: 6 Apr 2021 8:49 EDT
Zach Taylor (ZachT124)
@ThomasSasnett Thank you. I am currently using a script to look for the latest .xlsx file in my downloads folder. But I need to be able to tell when that file hits my downloads folder so that I accidentally do not pick up a different file. The name of the file is dynamic and there isn't really a good way to look for the file name. That is why I was wanting to see if there was away to wait until the file is downloaded and in the downloads folder before I move and rename the file. I will get the File System Watcher another shot. I didn't have any luck with it before.
@ZachT124 The FSW will fire several events when a file is downloaded. You can use the one attached to see which events they are and wait for the appropriate one. It seems like the events fire relatively close to each other, so you might be able to wait for the last one and have a brief pause before you actually interact with the file to ensure it is always available.