At the moment I'm using >
filename = FileNameJoin[{root = "F:\\somefolderpath", file = "somefile.extention"}];
If[! DirectoryQ[root],
Print[Style["Directory '" <> root <> "' does not exist!", {Red, Bold, Large}]]; Quit[]];
If[! FileExistsQ[filename],
Print[Style["File '" <> filename <> "' does not exist!", {Red, Bold, Large}]]; Quit[]];
(*Start using 'filename'*)
edit: Ended up using
SafeFile::usage = "Use instead of Import.";
SafeFile::nodir = "Directory `1` does not exist.";
SafeFile::nofile = "File `1` does not exist.";
SafeFile[filename_,root_:NotebookDirectory[]]:=Module[{
fullfilename=FileNameJoin[{root,filename}]
},
If[!TrueQ@DirectoryQ@root,Message[SafeFile::nodir,root];Quit[]];
If[!TrueQ@FileExistsQ@fullfilename,Message[SafeFile::nofile,filename];Quit[]];
Import[fullfilename]
]
Quitting kernel was actually what I needed.
SafeFile::nodir, and you don't need to define them in your function; they can go right next to theSafeFile::usagedefinition. – Brett Champion Apr 13 '12 at 22:06