VBS code to copy file in all physical drives [Solved/Closed]

Kashyap_128 - Jun 24, 2010 at 09:48 PM - Latest reply:  Kashyap_128
- Jun 29, 2010 at 06:52 AM
Hello everyone,

Is there any code in VBScript that I can use to copy a file(s) in all physical drives at once without giving the driveletter(in a single line or two)?

The problem is that I couldnot find any VBS code that I could use to copy a single file to all physical drives & removable drives in a single line/sentence(s). I don't know much about VBS and I donot use any VB6/VB.net and I don't want to learn those VB6 or VB.net anyway.
Well, if you have any such code in batch also, please do mention it. If anyone knows the code, please explain in detail.

I do know about how to copy file in drives one by one (in VBS) but I don't know how to do it all at once in 1 line code.
Thanks everyone
See more 

5 replies

Best answer
Kashyap_128 - Jun 25, 2010 at 07:58 AM
2
Thank you
Exactly 5 hours earlier, I asked this very question and pasted it on this forum. But, I have discovered it myself using IsReady is the answer. The code would be


' This Sample copies the vbs file to all the existing drives.
' This sample gives an error "File already exists" since it finds a copy of itself already present in 1 of drives
' Using seperate name for duplicate copy prevents the error
' overwrite code maynot be working

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives

For Each objDrive in colDrives
If objDrive.IsReady = True Then
objfso.CopyFile "filename.vbs" , objDrive.DriveLetter+":\" , overwriting = true
End If
Next

Thank you, Kashyap_128 2

Something to say? Add comment

CCM has helped 1665 users this month

If one executes the vbs file code from within any folder inside a drive and not from the drive directly (eg. g:\folder1\sample.vbs not g:\sample.vbs), there'll be no error(s)
rizvisa1 4481 Posts Thursday January 28, 2010Registration dateContributorStatus January 6, 2016 Last seen - Jun 26, 2010 at 09:04 AM
Thank you for doing the thankless job of putting a solution. Though I do not need the solution, but I just wanted to appreciate your effort in taking time and answering your own question. I am sure, it would be useful to some one down the road.
Thank you for your comment rizvisa1. Actually, no-one would make a silly mistake of posting the solution in his own asked question.
But what I thought was that it could be a small help for someone (beginner) like me, trying to actually find some code.
Anyway, thank you for your comment ...
This is for beginners another simple code to copy in pendrive

' copy in flash drive
Const Removable = 1
Set FSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = FSO.Drives
For Each Drive in colDrives
If Drive.DriveType = Removable then
fso.copyfile "new.vbs" , Drive.DriveLetter&":\"
End if
Next

Use it with const fixed = 2 & one can get file copied to all fixed drives