We help IT Professionals succeed at work.

vbs to work on folder contains shortcuts to copy the source to another folder.

ethar1
ethar1 asked
on
hi,
I have a folder contains around 2000 shortcut for files separated all over network drives.
how can copy and past those files to a cd without go after each file.

I need a vb script.

thanks.
Comment
Watch Question

Top Expert 2007
Commented:
Let me know if this works for you...

'LocateSC.vbs

'' /// Setup environment declarations and object references ///
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell:Set objShell = CreateObject("Wscript.Shell")
Dim objFolder:Set objFolder = objFSO.GetFolder("C:\Path of shortcuts\")
CDPath=objShell.ExpandEnvironmentStrings("%UserProfile%") & "\Local Settings\Application Data\Microsoft\CD Burning\"

' /// Run the main routine, ProcessFolder, a recursive search through the files/folders found in the objFolder reference ///
  ProcessFolder (objFolder)

' /// Destroy object references, finalizing the script ///
Set objFolder=Nothing
Set objShell=Nothing
Set objFSO=Nothing
wscript.quit

' /// Main routine to scan current folder and recursively call against sub folders ///
Sub ProcessFolder(fld)
  Set subFld = objFSO.GetFolder(fld) ' Set object reference against current folder
  ProcessFile (subFld) 'Call Processfile routine against current folder
  For Each fld In subFld.SubFolders 'loop through all subfolders, recalling the same routine
    ProcessFolder (fld)
  Next
End Sub

' /// Routine to process all container files within the passed folder reference
Sub ProcessFile(fld)
  Set objFld = objFSO.GetFolder(fld) 'create object reference to the current folder
  For Each file In objFld.Files 'loop through all files found
  If objFSO.GetExtensionName(file) = "lnk" Then 'if the extension is 'lnk', it's a shortcut - only proceed if this returns TRUE
    Set objFile = objShell.CreateShortcut(file) 'create a shell reference to the file
    objFSO.CopyFile objFile.TargetPath, CDPath 'Copy file to the CD burning cache
    Set objFile = Nothing 'destory object reference
  End If
Next
End Sub

Author

Commented:
permission denied
line 31
char 5
Top Expert 2007

Commented:
Still the error?  Wasn't sure since you've closed this out...let me know.

Author

Commented:
I give full permession to the target folder and it's work.
thanks.