Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

840 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