Solved

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

Posted on 2008-10-31
3
329 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now