Solved

Copy files from a CD to HD and reset read-only attribute

Posted on 2008-10-31
3
332 Views
Last Modified: 2012-08-14
Hi.  I need help with a script that simply copies folders (and files) from a CD to a folder structure on the hard drive.  I have the code to do this, but I can't run it multiple times as the original copy flags everything readonly.  How do I copy from the CD and NOT set the read only attribute on the HD?  Either that or how do I remove the read only flag onl the entire folder structure once copied over?

Thanks.
My code so far:
dim objFSO
dim objFolder
dim objShell


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

strDestFolder = "C:\Sales Presentation"

'  Delete Folder first
'If objFSO.FolderExists(strDestFolder) then
'    objFSO.DeleteFolder(strDestFolder)
'End If

'  Create new folder
If Not objFSO.FolderExists(strDestFolder) then
    objFSO.CreateFolder(strDestFolder)
End If
'msgbox (strDestFolder & " Folder Created.")

'  Get Drive Letter where presentation is stored.
strPath = objShell.CurrentDirectory
strInstallDrive = objFSO.GetDriveName(strPath)
Wscript.Echo strInstallDrive
strInstallDrive="D:"

'  copy files from CD to C:\ drive
objFSO.CopyFolder strInstallDrive & "\Sales Presentation\*.*" , strDestFolder , true
0
Comment
Question by:JasonJewett
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
SRigney earned 500 total points
ID: 22852555
Const READ_ONLY = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\Scripts\Computers.txt")

If objFile.Attributes AND READ_ONLY Then
    objFile.Attributes = objFile.Attributes XOR READ_ONLY
End If


Info pulled from http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan05/hey0118.mspx
0
 

Author Comment

by:JasonJewett
ID: 22852758
Thanks, but how do I do this for all files in the three subfolders as well?  I really like a way to copy them over without keeping the RO flag set instead of copying them over and then unflaging RO.

0
 
LVL 15

Assisted Solution

by:SRigney
SRigney earned 500 total points
ID: 22853023
I did something very similar several years ago.  I had a project where a company was sending files on a CD and we needed to process them.  I had to use the FileSystemObject to set each file to not be read only.

What I did was copy the entire CD over, then loop through all files in all subfolders from the destination and change this setting.  

Later I changed my other process to check if the file was read-only before it started to use it, then it would change it to not read-only, which allowed the handling of files step to take care of the read-only flag itself.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question