Solved

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

Posted on 2008-10-31
3
323 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

12 Experts available now in Live!

Get 1:1 Help Now