+ Post New Thread
Results 1 to 6 of 6
Scripts Thread, Display the name of a file in a message box in Coding and Web Development; Hi I would like some code that will display the name of a .txt file in a specific folder in ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,823
    Thank Post
    875
    Thanked 1,675 Times in 1,458 Posts
    Blog Entries
    12
    Rep Power
    444

    Display the name of a file in a message box

    Hi

    I would like some code that will display the name of a .txt file in a specific folder in a message box. Also to make it not to display the .txt format extension.

    Is this possible please?

    Thanks

    Z

  2. #2

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    Everything's possible :-)

    Not quite sure what you're trying to do (which file? where?) but this might help:

    Code:
    set ofso=createobject("scripting.filesystemobject")
    set oFolder=ofso.getfolder("c:\temp")
    for each oFile in oFolder.files
      if lcase(ofso.getextensionname(oFile.path))= "txt" then
        msgbox ofso.getbasename(oFile.path)
      end if
    next
    it steps through all the files in the folder. For each, it gets the full name (ofile.path) and then uses the getextensioname method to get the extension. If this is txt then it uses a message box to pop up the base part of the name (eg c:\temp\steve_file.txt will pop up steve_file)

  3. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,823
    Thank Post
    875
    Thanked 1,675 Times in 1,458 Posts
    Blog Entries
    12
    Rep Power
    444
    Just the job, cheers

    Everything's possible
    Have you got a script that will tidy my room

  4. #4

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,823
    Thank Post
    875
    Thanked 1,675 Times in 1,458 Posts
    Blog Entries
    12
    Rep Power
    444
    Just one question how would i get more text in there please? I would like a phrase just before it displays the file name.

    Thanks

  5. #5

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,401
    Thank Post
    637
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    319
    Code:
    set ofso=createobject("scripting.filesystemobject")
    set oFolder=ofso.getfolder("c:\temp")
    for each oFile in oFolder.files
      if lcase(ofso.getextensionname(oFile.path))= "txt" then
        msgbox "Tonight Matthew, the file name is: " & ofso.getbasename(oFile.path)
      end if
    next

  6. #6

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,823
    Thank Post
    875
    Thanked 1,675 Times in 1,458 Posts
    Blog Entries
    12
    Rep Power
    444
    Very Cheesy!

    Thanks!

SHARE:
+ Post New Thread

Similar Threads

  1. Display a message
    By FN-GM in forum Scripts
    Replies: 13
    Last Post: 15th February 2008, 10:35 PM
  2. Replies: 2
    Last Post: 29th January 2007, 03:25 PM
  3. Display a message whilst installing software
    By richard in forum How do you do....it?
    Replies: 14
    Last Post: 14th December 2006, 01:40 PM
  4. Replies: 2
    Last Post: 13th June 2006, 09:22 PM
  5. Replies: 4
    Last Post: 23rd March 2006, 06:27 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •