Windows offers a wide variety of tools that you can access using your command prompt window including the “attrib” tool which is designed to help you search for files by location and name then view and modify their file attributes.
What Attributes Can You Use?
Now that you have your elevated command prompt window open, you will need to know what types of attributes you can edit using the “attrib” tool. There are two main types of attributes, “basic” and “extended.”
Basic Attribute Switches (R, H, A, S)
R – This command will assign the “Read-Only” attribute to your selected files or folders. H – This command will assign the “Hidden” attribute to your selected files or folders. A – This command will prepare your selected files or folders for “Archiving. ” S – This command will change your selected files or folders by assigning the “System” attribute.
“Attrib” Syntax
You will need to know the proper syntax to use for the “attrib” tool before you get started.
In this syntax, you will need to know what the different switches and parameters represent.
The + and – indicate whether you will activate or deactivate the attribute specified. The attributes you can use are those explained above. The “/S” signifies that you want to search the entire path specified including subfolders for a particular file. The “/D” signifies that you want to include any process folders as well. The pathname indicates the location of your target folder or file. The proper syntax for path files is shown below.
If you decide not to specify any of the attributes listed above, the files or folders will revert to their current attribute settings.
Let’s Practice
Now that you know the types of attributes you can use and the syntax you need to use, let’s practice some scenarios. Open the start menu in Windows 7 and 10 or open the search function in Windows 8 and search for CMD. Next, right-click on it and then press “Run as administrator.” While you don’t need to open an elevated command prompt window, it will help you to avoid any confirmation dialog boxes.
Scenario 1 – Clear “Hidden and System” attributes with a single command to make your files or folders normal.
For this example, we will first create a file in your “Documents” directory called “sample.txt.” First, open up the directory and right-click somewhere in the window, move your mouse to the “New” section, click on “Text File,” and name the document “sample.”
Now go to your CMD window. We will change the file’s properties so that it is both a system file, and hidden. Do this by entering the following command.
Remember to substitute the “Martin” section of the path parameter with your computer’s username.
Once you have done this, you will notice that the file has disappeared from your documents folder. Now that we want to remove the System and Hidden file attributes from “sample.txt,” we will need to use the following simple command.
Note that if you try to enter the file name without a path, you will receive an error. You must remember to add the entire path to your command. Now, if you go back to your “Documents” directory, you will see the file in the list.
Scenario 2 – Make all text files in your “Downloads” folder read-only system files.
Now we will create a few sample text files in the “Downloads” directory and we will edit them using the “attrib” tool so that they all become read-only system files.
Once you have your sample text files created, it is time to use CMD to write a command that will change the attributes of all text files in a specified directory to “Read-Only and System.” For this, we will need to use wildcards to select all the text files. You can do this by using the command below. Remember to substitute the “Martin” section with your computer’s username.
Now you can open your downloads folder, right-click on one of the text files and then select properties. You will note that the file attributes have been changed. To remove these settings simply use the same command, but replace the plus signs with minus signs.
Scenario 3 – Prepare a file located on your desktop for archiving.
Let’s start by creating a sample text file on the desktop. Now, navigate to your CMD window and enter the following string to prepare the selected file for archiving.
Scenario 4 – Hide an entire Directory/Folder on your desktop.
Let’s say for example, you have sensitive data in a folder on your desktop called “Private,” and you want to hide it along with all its files and subfolders. It is important to note that when you are working with directory attributes, you cannot use wildcards such as “? and *.” You will need to be explicit in your file path. First, you need to create a folder on your desktop and put a few files in it. Once you have done that, navigate to your CMD window and enter the following command.
Once you press “Enter,” the entire folder will disappear since it will be hidden.
Now you can play with some of the other settings to make changes to any file attributes on your computer.