Loading files

Code builds a path to a specific file based on year and month and data station. It works fine when the 7 files are present. If a file is missing it errors and asks the user if they want to help find the file. I would like to avoid the needed user input by checking to see if the file is present before the Loadwave command is executed. If it's not present then execute the Else portion of the If statement and then move on.


 
FUNCTION LoadAB(yr,month,days)
	Variable yr, month, days
	Variable/G Arraylength
	Arraylength = days*1440
	string monnum, filepath, filepath1, filepath2
	variable flag=8
//	filepath = "P:Metdata:"	 //For use on a PC Replace the P: with the letter of the correct drive.

//This section builds the path to the file for the loadwave commamd
	filepath = "Mac Passport:Metdata:"  //For use om my MAC. Use the drive name.
		If(month < 10) //For single digit month numbers
			filepath1 =  num2str(yr)+":raw:QA:"
			filepath2 ="0"+num2str(Month) +"_CR1000_10A.txt"
		Else	//For 2 digit month numbers
			filepath1 = num2str(yr)+":raw:QA:"
			filepath2 = num2str(Month) +"_CR1000_10A.txt"
		EndIf
	filepath += filepath1; filepath += filepath2 //Builds the path for the loadwave command

	//The path to the file will look like this. The filename changes each month
		//Mac Passport:Metdata:2021:raw:QA:02_CR1000_10A.txt
	//If the file is present I want to load it and if it's not
	//print the file not found statement.
	

	IF(//What goes here)
		LoadWave/O/A/J/D/W/K=0/L={0,1,0,0,0}/R={English,2,2,2,2,"Year-Month-DayOfMonth",40}  filepath
		Wave Tmstamp, WS_10m, WD_10m, WD_SD_10m, WS10Gust, Temp_10m, Temp_2m, Baro_2m, RH_2m
		GetTime(Days)
		RevMissingLines10()
		Make /D/O/N=(arraylength, 9) Ten_A
		Ten_A[ ][0] = Tmstamp[p]
		Ten_A[ ][1] = WS_10m[p]
		Ten_A[ ][2] = WD_10m[p]
		Ten_A[ ][3] = WD_SD_10m[p]
		Ten_A[ ][4] = WS10Gust[p]
		Ten_A[ ][5] = Temp_10m[p]
		Ten_A[ ][6] = Temp_2m[p]
		Ten_A[ ][7] = Baro_2m[p]
		Ten_A[ ][8] = RH_2m[p]
		Else 
			Print "File not Found:", filepath
 	ENDIF

 

There are a couple of ways:

Open/R/Z=1 then check V_flag. It will be zero if the file was opened. Then call Close before calling LoadWave.

GetFileFolderInfo

I don't know which is faster, probably the GetFileFolderInfo operation; it is newer than Open by a number of years!