VB copy specific file from subfolder

Dell ?
June 23, 2009 at 09:34:57
Specs: Windows XP SP2, P4
Hi

I want to be able to eliminate the need for putting in the drive and folder name into the script below for example the 1st message box requires D:\July 08 which is the subfolder on the disk. This could be any month / year depending on what I need to reinstate. It's really bugging me as the script below works and I have another script that will echo all the details that I want but I can't combine them together.
I must confess my knowledge is very limited and everything I have built is copied and pasted from pretty much this forum. Any help much appreciated.

Code:


Option Explicit
Call letter
Sub Letter
Dim Fname, strDirectory, FSO, objfso, FSO2
strDirectory= Inputbox ("D Drive Directory Name")
--The above line is what I want to eliminate so it searches the subfolder and I

Fname= Inputbox ("Letter Number")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists (strDirectory & "\" & "R" & Fname & ".doc") Then
Const OverwriteExisting = True
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile strDirectory & "\" & "R" & Fname & ".doc" , "\\BRUSTR03\RUFUS\DATA\CORR\LGU\IMAGES\"
Else
WScript.Echo "File Doesn't Exist"
End If
If MsgBox("Do you have another letter to restore?", vbYesNo) = vbYes Then
Call Letter
Else
End If
End Sub

Thanks
bigb


See More: VB copy specific file from subfolder

Report •


#1
June 23, 2009 at 10:30:23
--The above line is what I want to eliminate so it searches the subfolder and I
I have no idea what you're trying to say here.

Dim Fname, strDirectory, FSO, objfso, FSO2
Dear God man, how many file system objects do you need?!


Report •

#2
June 24, 2009 at 02:55:26
Hi
Thank's for the reply, as I said, I have little to no knowledge and have ripped most of this off the forum (maybe I should look at learning from the basics!)
Ok what currently happens is a prompt box comes up and I input for example D:\July 08, another propt box come up then and I input the file number e.g 123456. What I want to do is eliminate the need to input D:\July 08 in the first prompt as on the disc there will only ever be 1 subfolder and just input the file number in to copy over.

As with the file system objects, I'll start reading up on them!

Thanks for any help
Cheers
bigb


Report •

#3
June 24, 2009 at 06:01:00
Disclaimer: This is an example of how terse you can be in VBScript. whether or not this is a good coding style is another matter.
Option Explicit
Dim d, fso : Set fso = CreateObject("Scripting.FileSystemObject")
Do 
  For Each d In fso.GetFolder("D:\").SubFolders
    d.Files("R" & Inputbox ("Letter Number") & ".doc").Copy _ 
      "\\BRUSTR03\RUFUS\DATA\CORR\LGU\IMAGES\", True
  Next 'd
Loop While MsgBox("Do you have another letter to restore?", vbYesNo) = vbYes


Report •

Related Solutions

#4
June 24, 2009 at 06:28:28
Razor 2.3, your a gentleman and a scholar, works perfectly.

I promise to learn from the begining!

Cheers
bigb


Report •


Ask Question