Home > SSIS > Changing Files and Folders Attribute using SSIS – Integration Services – SQL SERVER

Changing Files and Folders Attribute using SSIS – Integration Services – SQL SERVER


We know there are two types of attributes available for file and folder in windows system. Those are Read Only and Hidden. Read Only attribute setting assign read only access to a file or folder and we cannot delete it. In the same way Hidden attribute settings hides a file or folder from the users eyes.

Recently, I was asked to design a package to read and update all files in a folder and sub-folders in a directory. But, files and folders in that directory has read-only access. So, I could update those files. I know, we can use script task and write a piece of code using file system object to change the file attribute in this situation. But, I am lazy person and want to do everything in simple method. When I say the word lazy,  Bill Gates quote about lazy person comes from my memory. let talk about my solution.

I remember a command prompt command name Attrib. This command is used to manages files and folders attribute property. So, I just used this command in Execute Process Task to remove read only attribute property from all files in that directory and complete my file update operation and then I set Read Only attribute to all files again.

Attrib command and it’s argument definition.

pic6

Implementation

I am using my test folder named MyFiles. In this directory I have 4 text files, 2 of them are in root directory and other 2 are in a sub-folder. Below given image shows my folder structure.

pic1

Steps to use Attrib command in Execute Process Task.

1: Create a empty package and add Execute Process Task

pic2

Step 2: Edit this task and fill the values to the necessary property.

pic3

Properties used in this task

Executable : C:\Windows\System32\Attrib.exe

Arguments : -r /s

WorkingDirectory : [Root folder]

Step 3: Execute the package and see the attributes of the files.

pic5

I think you do like this method. If you want to apply Read Only property again to all files in  the directory than use the Execute Process Task and use the following values for the necessary property.

Executable : C:\Windows\System32\Attrib.exe

Arguments :  +r /s

WorkingDirectory : [Root folder]

I believe, this blog post help you in your project and saves your time. Happy coding!

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: