2

I'm attempting to get a list of files on a shared folder (with their complete path names)- for example, instead of

File1.txt 

File2.txt

on \\sharename\foldername, I'm trying to get:

D:\something\foldername\File1.txt

D:\something\foldername\File2.txt

The answer to this question (How to get the fully qualified path of a share in windows) was helpful, and shows how to get the real drive paths for shares using WMIC., but I'd like to go a little further for more info on the files within the share. Note- the share will be accessed locally, but there are multiple drive letters and I'm trying to avoid hard-coding any paths in a script.

2
  • What are you using? VBscript? jScript? Powershell? Python? C#?
    – surfasb
    Oct 27, 2011 at 7:59
  • Right now just a plain old batch file, but could use powershell instead. Ultimately it will be part of a SQL Server agent job that calls NetBackup to start a tape push on a shared folder (without having to specify drive letter)- using shared folders with NetBackup seems to work fine in Windows Server 2008 but not 2008 R2. Was thinking of generating a text file with a listing of the fully qualified file paths/names in a shared folder and then using that as a list of what to back up.
    – Emily
    Oct 27, 2011 at 13:05

2 Answers 2

4

If you have PowerShell installed, you can do:

get-childitem \\share\drive -Recurse| foreach-object -process { $_.FullName }
1
  • Thanks! That helps. In this case I'm using a share called "\\SID\SID_Backup\" and its local path is "B:\SID_Backup\" - assuming I didn't know that it was the B drive, do you know if it's possible to have it return the file paths with a drive letter in place of \\share\drive?
    – Emily
    Oct 27, 2011 at 13:09
0

Managed to get it working in VBscript, but powershell would be preferred. I've never worked with VBscript before, so yes it's probably inefficient and messy.

Input is \share\folder\folder and its creates a list of files in that folder.

    Dim Arg 
    Set Arg = WScript.Arguments

    strPath = WScript.Arguments(0)
    strPath = Replace(strPath, "\\", "")
    arrPath = Split(strPath, "\")
    strComputer = arrPath(0)
    strShare = arrPath(1)
    strFolder = arrPath(2)

    strPath0 = WScript.Arguments(0)
    sDate = Replace(Date, "/", "-") 
    filename = strPath0 & "\BackupFileList-" & sDate & ".txt"

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.CreateTextFile(filename, ForAppending, True)

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery _
        ("Select * From Win32_Share Where Name = '" & strShare & "'")

    For Each objItem in colItems
    dirPath =  objItem.Path
    Next

    Set folder = objFSO.GetFolder(WScript.Arguments(0))
    Set files = folder.Files

    For each folderIdx In files
        objTextFile.WriteLine(dirPath & "\" & strFolder & "\" & folderIdx.Name)
      Next
      objTextFile.Close

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .