private void File_SetAttributes(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var folder = tempRoot.CreateRecursiveTree(5); Console.WriteLine("Input Directory Path: [{0}]", folder); foreach (var fullPath in System.IO.Directory.EnumerateFileSystemEntries(folder.FullName, "*", System.IO.SearchOption.AllDirectories)) { System.IO.File.SetAttributes(fullPath, System.IO.FileAttributes.Normal); const System.IO.FileAttributes attributes = System.IO.FileAttributes.Hidden | System.IO.FileAttributes.Archive | System.IO.FileAttributes.System | System.IO.FileAttributes.ReadOnly; Alphaleonis.Win32.Filesystem.File.SetAttributes(fullPath, attributes); var sysIO = System.IO.File.GetAttributes(fullPath); // Remove Directory attribute for comparing. var noDir = sysIO; noDir &= ~System.IO.FileAttributes.Directory; Assert.AreEqual(attributes, noDir); Assert.AreEqual(sysIO, Alphaleonis.Win32.Filesystem.File.GetAttributes(fullPath)); } } Console.WriteLine(); }
public virtual void Refresh() { try { switch (this.source) { case Source.Attributes: System.IO.FileAttributes attributes = NativeMethods.FileManagement.GetFileAttributes(this.Path); this.PopulateData(this.Path, attributes); break; case Source.FindResult: var findResult = NativeMethods.FileManagement.FindFirstFile(this.Path); this.PopulateData(findResult); findResult.FindHandle.Close(); break; case Source.FileInfo: using (SafeFileHandle fileHandle = GetFileHandle(this.Path)) { NativeMethods.FileManagement.BY_HANDLE_FILE_INFORMATION info = NativeMethods.FileManagement.GetFileInformationByHandle(fileHandle); this.PopulateData(this.Path, fileHandle, info); } break; } } catch (System.IO.FileNotFoundException) { this.Exists = false; } }
private void StartButton_Click(object sender, EventArgs e) { // this is where the start button comes to . StartButton.Enabled = false; SinTreeAutoClassification.SinTreeAutoClassification autoClassification = new SinTreeAutoClassification.SinTreeAutoClassification(intensityEstimation, neighbourhoodEstimation, sourceClasses, treeLocations); System.IO.FileAttributes attr = System.IO.File.GetAttributes(lasFilePath); // dir if (attr.HasFlag(System.IO.FileAttributes.Directory)) { string[] files = System.IO.Directory.GetFiles(lasFilePath, "*.las"); foreach (string lasFile in files) { // for each file, run classify autoClassification.Classify(lasFile); } } //file else { if (System.IO.File.Exists(lasFilePath)) { autoClassification.Classify(lasFilePath); } else { MessageBox.Show(String.Format("{0}{1}File not exists!", lasFilePath, Environment.NewLine), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } autoClassification.Dispose(); MessageBox.Show("Classification Done!", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); StartButton.Enabled = true; }
static System.IO.FileAttributes GetFileAttributes(string path, out MonoIOError error) { //Formatter.WriteLine("MonoIO: GetFileAttributes: called with path: " + path, Program.arch.DebugOutput); while (Program.Vfs == null) { ; } /*if (Program.Vfs == null) * { * error = MonoIOError.ERROR_GEN_FAILURE; * return InvalidFileAttributes; * }*/ //System.IO.FileAttributes fa = (System.IO.FileAttributes)Program.Vfs.Invoke("GetFileAttributes", new object[] { path }, File.sig_vfs_GetFileAttributes); System.IO.FileAttributes fa = Program.Vfs.GetFileAttributes(path).Sync(); if (fa == InvalidFileAttributes) { error = MonoIOError.ERROR_FILE_NOT_FOUND; } else { error = MonoIOError.ERROR_SUCCESS; } return(fa); }
/// <summary> /// 设置文件可写 /// </summary> public static bool SetFileWritable(string filePath) { string fullPath = filePath; //convert assetPath to absolute path if (fullPath.StartsWith("Assets/")) { fullPath = AssetPathToAbsPath(fullPath); } try { System.IO.FileAttributes fa = System.IO.File.GetAttributes(fullPath); if (fa.HasFlag(System.IO.FileAttributes.ReadOnly)) { System.IO.File.SetAttributes(fullPath, System.IO.FileAttributes.Normal); } return(true); } catch (System.Exception e) { Debug.LogErrorFormat("Fail to set file({0}) be writable, for the reason of {1}", filePath, e.Message); return(false); } }
public bool IsDirectory(string Path) { try { System.IO.FileAttributes attr = System.IO.File.GetAttributes(Path); if ((attr & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory) { return(true); } else { return(false); } } catch { if (System.IO.Path.HasExtension(Path)) { return(true); } else { return(false); } } }
private bool IsFileSystemItemShown(System.IO.FileAttributes Attributes, bool ShowSystem, bool ShowHidden) { bool Show = true; if ((Attributes & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden) { if (ShowHidden) { Show &= true; } else { Show &= false; } } if ((Attributes & System.IO.FileAttributes.System) == System.IO.FileAttributes.System) { if (ShowSystem) { Show &= true; } else { Show &= false; } } return(Show); }
/// <summary> /// Removes the read only flag from the asset. /// </summary> /// <returns><c>true</c>, if read only flag was removed, <c>false</c> otherwise.</returns> /// <param name="path">Path.</param> public static bool RemoveReadOnlyFlag(string path) { if (string.IsNullOrEmpty(path)) { return(false); } // Clear the read-only flag in texture file attributes if (System.IO.File.Exists(path)) { #if !UNITY_4_1 && !UNITY_4_0 && !UNITY_3_5 if (!AssetDatabase.IsOpenForEdit(path)) { Debug.LogError(path + " is not editable. Did you forget to do a check out?"); return(false); } #endif System.IO.FileAttributes texPathAttrs = System.IO.File.GetAttributes(path); texPathAttrs &= ~System.IO.FileAttributes.ReadOnly; System.IO.File.SetAttributes(path, texPathAttrs); return(true); } // Default return(false); }
private static extern bool PathRelativePathTo( [Out] StringBuilder pszPath, [In] string pszFrom, [In] System.IO.FileAttributes dwAttrFrom, [In] string pszTo, [In] System.IO.FileAttributes dwAttrTo );
internal static FileInfo GetFileInfoCore(string path, System.IO.FileAttributes attributes, FileAttributes fileAttributes, bool checkInvalidPathChars, bool continueOnException) { // Prevent possible crash. var fileInfo = new FileInfo { DisplayName = string.Empty, TypeName = string.Empty, IconIndex = 0 }; if (!Utils.IsNullOrWhiteSpace(path)) { // ShGetFileInfo() // In the ANSI version of this function, the name is limited to 248 characters. // To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. // 2013-01-13: MSDN does not confirm LongPath usage but a Unicode version of this function exists. // However, the function fails when using Unicode format. var shGetFileInfo = NativeMethods.ShGetFileInfo(Path.GetRegularPathCore(path, checkInvalidPathChars ? GetFullPathOptions.CheckInvalidPathChars : 0, false), attributes, out fileInfo, (uint)Marshal.SizeOf(fileInfo), fileAttributes); if (shGetFileInfo == IntPtr.Zero && !continueOnException) { NativeError.ThrowException(Marshal.GetLastWin32Error(), path); } } return(fileInfo); }
} // End Function CloseRepository // Since NGit is a port from Java, it doesn’t implement IDisposable when accessing files. // To remove its lock on files, you can dispose of the Git object by doing the following: public virtual bool CloseRepository(NGit.Api.Git repository, bool resetAttributes) { // NGit.Api.Git repository = NGit.Api.Git.Open (@"C:\Git\NGit"); // Handle disposing of NGit's locks repository.GetRepository().Close(); repository.GetRepository().ObjectDatabase.Close(); repository = null; if (resetAttributes) { string[] files = System.IO.Directory.GetFiles(@"C:\Git\NGit", "*", System.IO.SearchOption.AllDirectories); // You may also want to recursively remove any read-only file attributes set by NGit in the repository’s path // if you need to remove the repository later or you will receive permission exceptions when attempting to do so. // Remove the read-only attribute applied by NGit to some of its files // http://stackoverflow.com/questions/7399611/how-to-remove-a-single-attribute-e-g-readonly-from-a-file foreach (string file in files) { System.IO.FileAttributes attributes = System.IO.File.GetAttributes(file); if ((attributes & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly) { attributes = RemoveAttribute(attributes, System.IO.FileAttributes.ReadOnly); // file.Attributes = System.IO.FileAttributes.Normal; System.IO.File.SetAttributes(file, attributes); } // End if ((attributes & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly) } // Next file } // End if (resetAttributes) return(true); } // End Function CloseRepository
public override void Exec(vsCommandExecOption executeOption, ref object varIn, ref object varOut) { string magicDrawPath = m_addInSettings.UMLModellerPath; if (magicDrawPath != string.Empty && System.IO.File.Exists(magicDrawPath) && System.IO.File.Exists(m_solutionManager.ModelFilePath)) { try { if (m_addInSettings.AutoMakeModelFileWritable) { System.IO.FileAttributes attr = System.IO.File.GetAttributes(m_solutionManager.ModelFilePath); if ((attr & System.IO.FileAttributes.ReadOnly) != 0) { attr -= System.IO.FileAttributes.ReadOnly; System.IO.File.SetAttributes(m_solutionManager.ModelFilePath, attr); } } //AddInUtils.ShowWarning("Path: " + magicDrawPath + "\nArgs: " + "\"" + m_solutionManager.ModelFilePath + "\""); System.Diagnostics.Process.Start(magicDrawPath, "\"" + m_solutionManager.ModelFilePath + "\""); } catch (Exception e) { AddInUtils.ShowError("An unexpected error occured while trying to launch the external UML modeling tool: " + e.Message); } } else { AddInUtils.ShowError("The external UML modeling tool could not be found. Please ensure the path is correct in the Android/VS options page (Tools | Options | AndroMDA | Tools)"); } }
internal static FileInfo GetFileInfoCore(string path, System.IO.FileAttributes attributes, FileAttributes fileAttributes, bool checkInvalidPathChars, bool continueOnException) { // Prevent possible crash. var fileInfo = new FileInfo { DisplayName = string.Empty, TypeName = string.Empty, IconIndex = 0 }; if (!Utils.IsNullOrWhiteSpace(path)) { // ShGetFileInfo() // 2013-01-13: MSDN does not confirm LongPath usage but a Unicode version of this function exists. // 2015-07-17: This function does not support long paths. var shGetFileInfo = NativeMethods.ShGetFileInfo(Path.GetRegularPathCore(path, checkInvalidPathChars ? GetFullPathOptions.CheckInvalidPathChars : 0, false), attributes, out fileInfo, (uint)Marshal.SizeOf(fileInfo), fileAttributes); if (shGetFileInfo == IntPtr.Zero && !continueOnException) { NativeError.ThrowException(Marshal.GetLastWin32Error(), path); } } return(fileInfo); }
private void deleteTempEntries(string _destinationPath, List <string> _zipList) {//Deletes anything that is not a matching zip file in the configuration text file. if (System.IO.Directory.Exists(_destinationPath)) { string[] entries = System.IO.Directory.GetFileSystemEntries(_destinationPath); int numOfEntries = entries.Length; for (int i = 0; i < numOfEntries; i++) { System.IO.FileAttributes attr = System.IO.File.GetAttributes(entries[i]); if ((!isMatchingZip(entries[i].ToLower(), _zipList)) && ((attr & System.IO.FileAttributes.Directory) != System.IO.FileAttributes.Directory)) { if (!entries[i].EndsWith(".xml")) { System.IO.File.Delete(entries[i]); } } else if (System.IO.Directory.Exists(entries[i])) { System.IO.Directory.Delete(entries[i], true); } } } else { return; } }
} // End Function IsSymLink private static bool IsSymLink(string path) { // get the file attributes for file or directory System.IO.FileAttributes attr = System.IO.File.GetAttributes(path); return(attr.HasFlag(System.IO.FileAttributes.ReparsePoint)); } // End Function IsSymLink
public int SetFileAttributes( string filename, System.IO.FileAttributes attr, DokanFileInfo info) { return(-1); }
public NtStatus SetFileAttributes( string filename, System.IO.FileAttributes attr, DokanFileInfo info) { return(DokanResult.Error); }
static bool FileDelete(string path) { //first set the File's ReadOnly to 0 //if EXP, restore its Attributes System.IO.FileInfo file = new System.IO.FileInfo(path); System.IO.FileAttributes att = 0; bool attModified = false; try { //### ATT_GETnSET att = file.Attributes; file.Attributes &= (~System.IO.FileAttributes.ReadOnly); attModified = true; file.Delete(); } catch (Exception e) { if (attModified) { file.Attributes = att; } return(false); } return(true); }
public virtual void Refresh() { try { switch (_source) { case Source.Attributes: System.IO.FileAttributes attributes = (System.IO.FileAttributes)Storage.GetFileAttributesExtended(Paths.AddExtendedPrefix(Path)).FileAttributes; PopulateData(Path, attributes); break; case Source.FindResult: case Source.FileInfo: using (SafeFileHandle fileHandle = GetFileHandle(Path)) { var info = Storage.GetFileBasicInformation(fileHandle); PopulateData(Path, fileHandle, info); } break; } } catch (System.IO.FileNotFoundException) { Exists = false; } }
} // End Function IsReadOnly private static void SetReadOnlyAttribute(string strFileName, bool readOnly) { System.IO.FileInfo fiThisFile = new System.IO.FileInfo(strFileName); if (!fiThisFile.Exists) { fiThisFile = null; return; } // End if (!fiThisFile.Exists) System.IO.FileAttributes old_attributes = fiThisFile.Attributes; System.IO.FileAttributes new_attributes = old_attributes; if (readOnly) { new_attributes |= System.IO.FileAttributes.ReadOnly; // new_attributes = fiThisFile.Attributes | System.IO.FileAttributes.ReadOnly; } else { new_attributes &= ~System.IO.FileAttributes.ReadOnly; //new_attributes = (System.IO.FileAttributes)(fiThisFile.Attributes - System.IO.FileAttributes.ReadOnly); } //new_attributes ^= System.IO.FileAttributes.ReadOnly; // This toggles value, not unset... if (old_attributes != new_attributes) // Don't perform operation if not necessary { System.IO.File.SetAttributes(fiThisFile.FullName, new_attributes); } fiThisFile = null; } // End Sub SetReadOnlyAttribute
public bool SelectFile(string filepath, bool canReturn, bool append = false) { if (this.multifile == false) { append = false; } foreach (FileBrowserArea fba in this.browserAreas) { fba.SelectFile(filepath, append); } if (string.IsNullOrEmpty(filepath) == false) { System.IO.FileAttributes fileSelAttr = System.IO.File.GetAttributes(filepath); if ( this.singleClickFolder == true && fileSelAttr.HasFlag(System.IO.FileAttributes.Directory) == true) { this.ViewDirectory(filepath, NavigationType.SelectBrowser, true); } else if (this.singleClickFile == true && canReturn == true) { this.ReturnFile(filepath); } } return(true); }
/// <summary> /// Combine all sprites into a single texture and save it to disk. /// </summary> static Texture2D UpdateTexture(UIAtlas atlas, List <SpriteEntry> sprites) { // Get the texture for the atlas Texture2D tex = atlas.texture as Texture2D; string oldPath = (tex != null) ? AssetDatabase.GetAssetPath(tex.GetInstanceID()) : ""; string newPath = NGUIEditorTools.GetSaveableTexturePath(atlas); // Clear the read-only flag in texture file attributes if (System.IO.File.Exists(newPath)) { System.IO.FileAttributes newPathAttrs = System.IO.File.GetAttributes(newPath); newPathAttrs &= ~System.IO.FileAttributes.ReadOnly; System.IO.File.SetAttributes(newPath, newPathAttrs); } if (tex == null || oldPath != newPath) { // Create a new texture for the atlas tex = new Texture2D(1, 1, TextureFormat.ARGB32, false); // Pack the sprites into this texture PackTextures(tex, sprites); byte[] bytes = tex.EncodeToPNG(); System.IO.File.WriteAllBytes(newPath, bytes); bytes = null; // Load the texture we just saved as a Texture2D AssetDatabase.Refresh(); tex = NGUIEditorTools.ImportTexture(newPath, false, true); // Update the atlas texture if (tex == null) { Debug.LogError("Failed to load the created atlas saved as " + newPath); } else { atlas.spriteMaterial.mainTexture = tex; } } else { // Make the atlas readable so we can save it tex = NGUIEditorTools.ImportTexture(oldPath, true, false); // Pack all sprites into atlas texture PackTextures(tex, sprites); byte[] bytes = tex.EncodeToPNG(); System.IO.File.WriteAllBytes(newPath, bytes); bytes = null; // Re-import the newly created texture, turning off the 'readable' flag AssetDatabase.Refresh(); tex = NGUIEditorTools.ImportTexture(newPath, false, false); } AssetDatabase.SaveAssets(); Resources.UnloadUnusedAssets(); return(tex); }
public static extern IntPtr CreateFile( [MarshalAs(UnmanagedType.LPTStr)] string filename, [MarshalAs(UnmanagedType.U4)] System.IO.FileAccess access, [MarshalAs(UnmanagedType.U4)] System.IO.FileShare share, IntPtr securityAttributes, // optional SECURITY_ATTRIBUTES struct or IntPtr.Zero [MarshalAs(UnmanagedType.U4)] System.IO.FileMode creationDisposition, [MarshalAs(UnmanagedType.U4)] System.IO.FileAttributes flagsAndAttributes, IntPtr templateFile);
public void SetAttributes(string path, System.IO.FileAttributes attributes) { if (path == null) { throw new ArgumentNullException(nameof(path)); } Storage.SetFileAttributes(Paths.AddExtendedPrefix(NormalizeIfNotExtended(path)), (FileAttributes)attributes); }
public IEnumerable <IFileSystemInformation> EnumerateChildren( ChildType childType = ChildType.File, string searchPattern = "*", System.IO.SearchOption searchOption = System.IO.SearchOption.TopDirectoryOnly, System.IO.FileAttributes excludeAttributes = System.IO.FileAttributes.Hidden | System.IO.FileAttributes.System | System.IO.FileAttributes.ReparsePoint) { return(EnumerateChildrenInternal(this.Path, childType, searchPattern, searchOption, excludeAttributes, this.FileService)); }
protected void PopulateData(string path, System.IO.FileAttributes attributes) { _source = Source.Attributes; Path = path; Name = path; Attributes = attributes; Exists = true; }
internal static extern SafeFileHandle CreateFile( string lpFileName, [MarshalAs(UnmanagedType.U4)] System.IO.FileAccess dwDesiredAccess, [MarshalAs(UnmanagedType.U4)] System.IO.FileShare dwShareMode, IntPtr lpSecurityAttributes, [MarshalAs(UnmanagedType.U4)] System.IO.FileMode dwCreationDisposition, [MarshalAs(UnmanagedType.U4)] System.IO.FileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
public void SetAttributes(string path, System.IO.FileAttributes attributes) { if (path == null) { throw new ArgumentNullException(nameof(path)); } NativeMethods.FileManagement.SetFileAttributes(path, attributes); }
internal static extern Microsoft.Win32.SafeHandles.SafeFileHandle CreateFile( string fileName, [MarshalAs(UnmanagedType.U4)] EFileAccess fileAccess, [MarshalAs(UnmanagedType.U4)] System.IO.FileShare fileShare, IntPtr securityAttributes, [MarshalAs(UnmanagedType.U4)] System.IO.FileMode creationDisposition, [MarshalAs(UnmanagedType.U4)] System.IO.FileAttributes flags, IntPtr template);
static extern SafeFileHandle CreateFile( string fileName, System.IO.FileAccess desiredAccess, System.IO.FileShare shareMode, IntPtr securityAttributes, System.IO.FileMode creationDisposition, System.IO.FileAttributes flagsAndAttributes, SafeFileHandle templateFile);
public INode(int index, System.IO.FileAttributes attribute) { this.index = index; this.attribute = attribute; sizeByte = 0; blocks = new List<Block>(); creationTime = DateTime.Now; lastAccessTime = creationTime; lastWriteTime = creationTime; }
public DirectoryItem(String name, String path, int inodeIndex) { INode inode = Disk.iNodes[inodeIndex]; this.name = name; this.path = path; this.size = inode.sizeByte; this.attribute = inode.attribute; this.creationTime = inode.creationTime; this.lastAccessTime = inode.lastAccessTime; this.lastWriteTime = inode.lastWriteTime; }
internal void From(NativeMethods.WIN32_FIND_DATA findData) { fileAttributes = findData.dwFileAttributes; ftCreationTime = findData.ftCreationTime; ftLastAccessTime = findData.ftLastAccessTime; ftLastWriteTime = findData.ftLastWriteTime; fileSizeHigh = findData.nFileSizeHigh; fileSizeLow = findData.nFileSizeLow; }
public FileAttributes(object attrs) { if (isLinux) { sys_attrs = (System.IO.FileAttributes)attrs; } else { delim_attrs = (Delimon.Win32.IO.FileAttributes)attrs; } }
public void PopulateFrom(NativeMethods.WIN32_FIND_DATA findData) { fileAttributes = findData.dwFileAttributes; ftCreationTimeLow = (uint)findData.ftCreationTime.dwLowDateTime; ftCreationTimeHigh = (uint)findData.ftCreationTime.dwHighDateTime; ftLastAccessTimeLow = (uint)findData.ftLastAccessTime.dwLowDateTime; ftLastAccessTimeHigh = (uint)findData.ftLastAccessTime.dwHighDateTime; ftLastWriteTimeLow = (uint)findData.ftLastWriteTime.dwLowDateTime; ftLastWriteTimeHigh = (uint)findData.ftLastWriteTime.dwHighDateTime; fileSizeHigh = findData.nFileSizeHigh; fileSizeLow = findData.nFileSizeLow; }