locked
Simply listing files on a NAS share using VBS RRS feed

  • Question

  • I have yet to find a webpage, article, or forum that gives insight on something I am sure other people have tried to do. Basically just list the files in a directory on a NAS share using VBS.  I can do it in BATCH but not VBS.  Can anyone, ANYONE, point me in the right direction. I can't seem to find documentation anywhere.

    admin



    • Edited by dewinthedew Tuesday, August 19, 2014 6:05 PM
    Tuesday, August 19, 2014 6:03 PM

Answers

  • You should really take the time to do the tutorial. You still do not know the basics of VBScript.

    strYear=Year(Now)
    strMonth=Month(Now)
    strFolder = "\\share_name\AP Data\AP Test Data\Output" & "\" & strYear & "\" & strMonth 
    
    set fso = CreateObject("scripting.FileSystemObject")
    set objFolder = fso.getFolder(strFolder)
    MsgBox "Number of files:" & objFolder.Files.Count
    For each fi In objFolder.Files
         msgbox fi.Name
    Next


    ¯\_(ツ)_/¯


    • Edited by jrv Tuesday, August 19, 2014 6:43 PM
    • Proposed as answer by jrv Tuesday, August 19, 2014 6:53 PM
    • Marked as answer by ScriptingWife Tuesday, September 16, 2014 6:41 PM
    Tuesday, August 19, 2014 6:43 PM

All replies

  • Hi

    The thread provided lists open files but im sure you can modify it to suite your needs:

    http://gallery.technet.microsoft.com/scriptcenter/91036496-bfbb-4e0c-a923-d484af48ace2/view/Reviews

    Tuesday, August 19, 2014 6:10 PM
  • yeah I saw and tried that. didn't work at all.


    Also there is nothing in that code for NAS shares specifically

    admin

    Tuesday, August 19, 2014 6:14 PM
  • I think the part that eludes me is connecting to the NAS shares and their subdirectories to be able to just list the files. I'm sure I'm not the only person that has tried to do this via VBS.

    admin

    Tuesday, August 19, 2014 6:16 PM
  • List files - not list open files.

    Sheesh...

    Here is a basic tutorial  http://technet.microsoft.com/library/ee176983.aspx


    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 6:16 PM
  • I think the part that eludes me is connecting to the NAS shares and their subdirectories to be able to just list the files. I'm sure I'm not the only person that has tried to do this via VBS.

    admin

    There is no difference between a NAS and any other file system.


    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 6:17 PM
  • on the contrary. I can do this for a drive on the same server or another server in a directory but for some reason its' not working for the NAS share. 

    admin

    Tuesday, August 19, 2014 6:20 PM
  • I am wondering if I need some other WMI object. Like a network object or something.

    admin

    Tuesday, August 19, 2014 6:21 PM
  • I am wondering if I need some other WMI object. Like a network object or something.

    admin


    What can you do that I not working?  We cannot guess.

    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 6:26 PM
  • oh and that tutorial you posted I can do blind folded :)

    admin

    Tuesday, August 19, 2014 6:26 PM
  • oh and that tutorial you posted I can do blind folded :)

    admin


    That is the problem then.  You cannot see the results with a blindfold on.  Take off the blindfold.

    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 6:28 PM
  • here's the kicker man. I set up a for loop and echo'd each variable loop value as well as messagbox each value but both the echo and messagebox's come up blank and the files are definitely in there. 

    admin

    Tuesday, August 19, 2014 6:29 PM
  • Without a script there is no way to know what you are talking about.


    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 6:30 PM
  • as always jrv you have sarcastic jokes. :)  it's not permissions I checked that. you sure i don't need any other wmi object?

    admin

    Tuesday, August 19, 2014 6:31 PM
  • .......... 

    set WshShell = Wscript.CreateObject("WScript.Shell") 
    set currentDate = WshShell.Exec( "cmd /C echo %date%") 
    currentDate = currentDate.Stdout.Readline
    cstr(currentDate)
    monthYear = replace(currentDate,"/","")
    spacePosition = Instr(monthYear," ")
    yearString = mid(monthYear,spacePosition+5,4)
    monthString = mid(monthYear,spacePosition+1,2)

    strFolder = "\\share_name\AP Data\AP Test Data\Output" & "\" & yearString & "\" & monthString 
    set fso = CreateObject("scripting.FileSystemObject")
    set objFolder = fso.getFolder(strFolder)

    Wscript.echo strFolder

    set fileCollection = objFolder.Files
    For each fil in fileCollection
    msgbox fil
    next


    admin

    Tuesday, August 19, 2014 6:34 PM
  • yes of course. Sorry man. there you go

    admin

    Tuesday, August 19, 2014 6:34 PM
  • as always jrv you have sarcastic jokes. :)  it's not permissions I checked that. you sure i don't need any other wmi object?

    admin

    You cannot use WMI on a NAS share.  |It is a file system issue.  Please review the tutorial on how to list files in the file system.  The FSO takes UNC paths as well as local drive references.

    All of this is basic Windows.   It has nothing to do with NAS or anything else.


    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 6:35 PM
  • .......... 

    set WshShell = Wscript.CreateObject("WScript.Shell") 
    set currentDate = WshShell.Exec( "cmd /C echo %date%") 
    currentDate = currentDate.Stdout.Readline
    cstr(currentDate)
    monthYear = replace(currentDate,"/","")
    spacePosition = Instr(monthYear," ")
    yearString = mid(monthYear,spacePosition+5,4)
    monthString = mid(monthYear,spacePosition+1,2)

    strFolder = "\\share_name\AP Data\AP Test Data\Output" & "\" & yearString & "\" & monthString 
    set fso = CreateObject("scripting.FileSystemObject")
    set objFolder = fso.getFolder(strFolder)

    Wscript.echo strFolder

    set fileCollection = objFolder.Files
    For each fil in fileCollection
    msgbox fil
    next


    admin

    What is this.  It is a jumble of pasted bits and it does not use the FO as shown in th tutorial.  Please review how to list files.

    If there are no files in a folder then there will be no output.


    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 6:38 PM
  • yeah like i said I did that a thousand times with no problem on a server. I saw what you call "basic" and follow that protocol so you don't have to remind me of what is "basic windows". right away I thought I had tp put a mapping command or something

    admin

    Tuesday, August 19, 2014 6:38 PM
  • dude what are you talking about? when strFolder is a local path or an actual drive on the server it works just fine. the NAS? not at all. and yes there are files in there smarty pants. 

    admin

    Tuesday, August 19, 2014 6:42 PM
  • You should really take the time to do the tutorial. You still do not know the basics of VBScript.

    strYear=Year(Now)
    strMonth=Month(Now)
    strFolder = "\\share_name\AP Data\AP Test Data\Output" & "\" & strYear & "\" & strMonth 
    
    set fso = CreateObject("scripting.FileSystemObject")
    set objFolder = fso.getFolder(strFolder)
    MsgBox "Number of files:" & objFolder.Files.Count
    For each fi In objFolder.Files
         msgbox fi.Name
    Next


    ¯\_(ツ)_/¯


    • Edited by jrv Tuesday, August 19, 2014 6:43 PM
    • Proposed as answer by jrv Tuesday, August 19, 2014 6:53 PM
    • Marked as answer by ScriptingWife Tuesday, September 16, 2014 6:41 PM
    Tuesday, August 19, 2014 6:43 PM
  • I basically whipped through this. this was not a question of now knowing basic windows because I do. it was a question of not checking my work.  my apologies mr judgmental and thank you. 

    I missed this part.

    msgbox fi.Name




    admin

    Tuesday, August 19, 2014 6:48 PM
  • I basically whipped through this. this was not a question of now knowing basic windows because I do. it was a question of not checking my work.  my apologies mr judgmental and thank you. 

    I missed this part.

    msgbox fi.Name




    admin

    Again - you are so certain that there is something wrong and not caused by you that you are very hard to help.  You really need to learn the basics.  The questions you ask shows you are missing important information about how Windows and VBScript works.

    Using CMD to get the date shoes you haven't even read the first couple of chapters of any tutorial.  Guessing will only waste your time.

    I am not being judgmental.  I am trying to get you to do your homework.


    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 6:53 PM
  • see this is where you are wrong and are assuming. I needed cmd to get me the double digit date format i needed because the folders are named after the month and year in double digits, created and formatted by another script. That fluctuates with the month because now() yields some months with a single digit.  i could sit here all day and go back and forth with you as we have done before but I have a date with a beautiful woman to attend to. :)  

    admin


    • Edited by dewinthedew Tuesday, August 19, 2014 6:57 PM
    Tuesday, August 19, 2014 6:56 PM
  • see this is where you are wrong and are assuming. I needed cmd to get me the double digit date format i needed because the folders are named after the month and year in double digits, created and formatted by another script. That fluctuates with the month because now() yields some months with a single digit.  i could sit here all day and go back and forth with you as we have done before but I have a date with a beautiful woman to attend to. :)  

    admin


    Again this is because you do not know the basics of scripting.

    strYear=Year(Now)
    strMonth
    =Right("0" & Month(Now),2)

    Simple as that.   Shelling takes a lot of code and endangers the whole script.

    One day you will see the basics and then understand what we are trying to point out to you.



    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 7:03 PM
  • Iv'e seen that and that will not work with this project because the sctript runs on pre-existing folders. some of them will have a 0 in front others will not (January will be 01, November will be 11). If I did what you just suggested and the script runs in November it would be looking for a folder with a month named (011) which we both know does not exist. What comes after this script will depend upon the name of the folders that were created based on the date. if i had time to sit and explain to you, you would completely understand. and YES you are being judgmental. dont' get me wrong, I get happy when you come online and help me because you are very very good but you can be a sort of a "not nice fellow" sometimes because you assume all of the facts that really have nothing to do what I have asked and draw conclusions.  So again as I told you, I know the basics and then some. 

    admin







    • Edited by dewinthedew Tuesday, August 19, 2014 7:29 PM
    Tuesday, August 19, 2014 7:08 PM
  • again - You are not paying attetntion and fail to understand because you insist that you already knowthe answer.

    This line always produces a two digit month.  Look closely at it.

    strMonth=Right("0" & Month(Now),2)

    This is what we all use and have been using  for many years. Learn the basics and you will understand.


    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 8:20 PM
  • ok I did look closely and I stand corrected. I just know of "now()" not Month(Now)

    hence the reason I used CMD. So

    I'll take that with me. Thank you. Much obliged. However the link to your

    "tutorial" mentions nothing of month(now). I would have had to have already

    known it and digged for it. This is not basic windows but a useful tip.

    Lets categorize things correctly before you proceed with condescending

    remarks.


    admin







    • Edited by dewinthedew Tuesday, August 19, 2014 8:44 PM
    Tuesday, August 19, 2014 8:40 PM
  • Stop being lazy and look at the whole tutorial.  There are hundreds of pages.  You just look at a few lines and claim to bean expert.

    http://technet.microsoft.com/en-us/scriptcenter/dd772284

    Without the basics you will forever be arguing with everyone.

    It is up to you.  IF you are too lazy to learn then that is you problem. 


    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 8:48 PM
  • Get real dude. We learn by doing more so by reading. :) You and I both know this. I am far from lazy. I am resourceful because time is of the essence. Surely not time to read and memorize a million page tutorial but I can search through it (which, by the way, yielded no results and wouldn't unless i knew what month(now) was).  I am sure you can appreciate that.   In any event, I have this bookmarked and will definitely go through it thoroughly when this project is finished. 

    Thanks again and it's been a pleasure learning and arguing with you. :)


    admin

    Tuesday, August 19, 2014 8:55 PM
  • So you admit that you cannot learn from a tutorial without memorizing,  How about you try to do the exercises until you "understand" the tutorial.  No one memorizes things.

    By doing the tutorial from beginning to end you will learn the basics.  By constantly guessing and pasting together code you clearly do not understand you are just making the whole experience more painful than it needs to be.

    I know. You will stubbornly shoot yourself in the foot reather than admit you are wrong.

    Good luck.


    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 9:02 PM
  • No dude the main point I was making is that I don't' have a lot of time, so I needed to find a very quick solution. If I do an initial search and that yields nothing I'll either post and ask questions to get a quick response or improvise (like using CMD).  Get that? Geesh. 

    admin

    Tuesday, August 19, 2014 9:05 PM
  • Sounds like a fourth grade excuse to me.

    Why are you newbies so averse to actually learning something. I don't understand.  YOu cannot be a tech if you cannot learn how to learn.


    ¯\_(ツ)_/¯

    Tuesday, August 19, 2014 9:11 PM