/** * Returns the file name (without the full path) */ public string getFileName() { if (InputStreamByteReader.isInputStream(filePath)) { return(string.Empty); // Input stream has no file name } else if (UrlByteReader.isURL(filePath)) { // File part of URL return(UrlByteReader.getURL(filePath).AbsolutePath); //.getFile(); } else { return(new System.IO.FileInfo(filePath).Name); //java.io.File(filePath)).getName(); } }
/** * Adds an element/elements to the collection * If filepath is a path to file then add that file * If filepath is a folder path then add contents of the folder * * @param theFile Filepath of file or folder * @param isRecursive if true add all subfolders and subsubfolders , etc */ public void addFile(string theFile, bool isRecursive) { if (UrlByteReader.isURL(theFile)) { if (!this.isDuplicate(theFile)) { //File object is a URL: add if it isn't a duplicate myFiles.Add(new IdentificationFile(theFile)); } return; } if (InputStreamByteReader.isInputStream(theFile)) { if (!this.isDuplicate(theFile)) { // File is a the input stram: add if it isn't a duplicate myFiles.Add(new IdentificationFile(theFile)); } } try { //java.io.File f = new java.io.File(theFile); System.IO.FileInfo f = new System.IO.FileInfo(theFile); //Is file object a directory or file? if (System.IO.Directory.Exists(theFile)) //f.isDirectory()) { //File object is a directory/folder //Iterate through directory ,create IdentificationFile objects //and add them to the collection //java.io.File[] folderFiles = f.listFiles(); System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(theFile); System.IO.FileInfo[] folderFiles = d.GetFiles(); int numFiles = 0; try { numFiles = folderFiles.Length; } catch (Exception) { MessageDisplay.GeneralWarning("Unable to read directory " + theFile + "\nThis may be because you do not have the correct permissions."); } for (int m = 0; m < numFiles; m++) { if (System.IO.Directory.Exists(folderFiles[m].FullName)) //folderFiles[m].isFile()) { //If file exists and not duplicate then add if (!this.isDuplicate(folderFiles[m].FullName)) { IdentificationFile idFile = new IdentificationFile(folderFiles[m].FullName); myFiles.Add(idFile); } } else if (System.IO.Directory.Exists(folderFiles[m].FullName) && isRecursive) { //If subdirectory found and recursive is on add contents of that folder addFile(folderFiles[m].FullName, isRecursive); } } } else if (!System.IO.Directory.Exists(f.FullName)) //f.isFile()) { if (!this.isDuplicate(f.FullName)) { //File object is a File then add file if it isn't a duplicate IdentificationFile idFile = new IdentificationFile(f.FullName); myFiles.Add(idFile); } } } catch (Exception e) { MessageDisplay.GeneralWarning("The following error occured while adding " + theFile + ":\n" + e.ToString()); } }