VBS code to copy file in all physical drives

Solved/Closed
Kashyap_128 - Jun 24, 2010 at 09:48 PM
 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

1 response

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
2
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)
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
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.
0
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 ...
0
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
0