+ Reply to Thread
Results 1 to 15 of 15

getting list of files in a directory into txt file

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office XP to Office 2016
    Posts
    1,549

    getting list of files in a directory into txt file

    Hi,

    The following script of a .bat file lists all files in a directory

    Please Login or Register  to view this content.
    While I want it to

    1: Look only in the directory "C:\Users\myPc\Dropbox" and its sub-directories
    2: List only .xlsm files that starts with "Imran*" which were modified within last week.


    Optional:

    Can we also list file properties with .bat file to txt file?
    Teach me Excel VBA

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs
    MS-Off Ver
    MS Office 2019
    Posts
    14,236

    Re: getting list of files in a directory into txt file

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office XP to Office 2016
    Posts
    1,549

    Re: getting list of files in a directory into txt file

    Thanks alan for your effort but I have a situation where I need a .bat file with dir command.
    The assistants will Run that file just by double clicking and email the created txt file to their Head.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs
    MS-Off Ver
    MS Office 2019
    Posts
    14,236

    Re: getting list of files in a directory into txt file


  5. #5
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office XP to Office 2016
    Posts
    1,549

    Re: getting list of files in a directory into txt file

    There is a lot to absorb and will let you know if I get my problem solved from the link.Currently reading "ADVANCED BATCH FILES" section.

  6. #6
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office XP to Office 2016
    Posts
    1,549

    Re: getting list of files in a directory into txt file

    Thanks for the link.

  7. #7
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    2,911

    Re: getting list of files in a directory into txt file

    I doubt you'll get what you want via a .bat file, but it's pretty easy via a .vbs file. Download the attached text file and change its extension to .vbs. Double-clicking on it will generate a file named 'FileList.txt' in your C:\Users\myPc\Dropbox folder. I'm not sure what file attributes you're after, but those could doubtless be added without much difficulty.

    PS: I'd have posted the code directly, but the forum software has a hissy-fit about a supposed exploit.
    Attached Files Attached Files
    Cheers,
    Paul Edstein
    [MS MVP - Word]

  8. #8
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office XP to Office 2016
    Posts
    1,549

    Re: getting list of files in a directory into txt file

    Exactly what I was after. much much appreciated and thanked


    Quote Originally Posted by macropod View Post
    I'm not sure what file attributes you're after, but those could doubtless be added without much difficulty.
    .
    I need "Tag","Last Auther","title" . how can I replicate your line for DateLastModified for these document properties?
    Please Login or Register  to view this content.

  9. #9
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    2,911

    Re: getting list of files in a directory into txt file

    For the extra details you could use the attached.
    Note: There is no built-in "Tag" property available through the Office API. The available properties for an Office file (some of which don't apply to Excel) are:

    Title
    Subject
    Author
    Keywords
    Comments
    Template
    Last Author
    Revision Number
    Application Name
    Last Print Date
    Creation Date
    Last Save Time
    Total Editing Time
    Number of Pages
    Number of Words
    Number of Characters
    Security
    Category
    Format
    Manager
    Company
    Number of Bytes
    Number of Lines
    Number of Paragraphs
    Number of Slides
    Number of Notes
    Number of Hidden Slides
    Number of Multimedia Clips
    Hyperlink Base
    Number of Characters (with spaces)
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office XP to Office 2016
    Posts
    1,549

    Re: getting list of files in a directory into txt file

    I am sorry but the later script is creating an empty FileList.txt

  11. #11
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    2,911

    Re: getting list of files in a directory into txt file

    I tested the code before posting and established that it works. Other than the additional lines for getting the file properties and the removal of two redundant code lines, it's fundamentally the same code as you successfully used before.

  12. #12
    Registered User
    Join Date
    01-09-2019
    Location
    nottingham
    MS-Off Ver
    office 16
    Posts
    9

    Re: getting list of files in a directory into txt file

    the website is backward
    CD C:/wherever_your_dir_is
    forfiles /s /c "cmd /c if STUPIDisdir==FALSE echo STUPIDpath STUPIDfsize" >>OutputFileDetails.txt

    but STUPID site is interpreting the "AT" sign as some kind of threat- replace STUPID with "at" as in the curly A

  13. #13
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    2,911

    Re: getting list of files in a directory into txt file

    So what has that to do with the OP's requirement? He doesn't want a text file of just file names as the output - he wants the output to show the author & title as well as the filenames...

  14. #14
    Registered User
    Join Date
    01-09-2019
    Location
    nottingham
    MS-Off Ver
    office 16
    Posts
    9

    Re: getting list of files in a directory into txt file

    oh come on, so rude, i'm what, under 10 posts in?
    1: Look only in the directory "C:\Users\myPc\Dropbox" and its sub-directories
    2: List only .xlsm files that starts with "Imran*" which were modified within last week.

    generates text file, from which you can get into CSV and go down the list. Do you know how to read text files into Excel, perhaps I'll show you next time. Off to bed.

  15. #15
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 2000/3/7/10/13/16
    Posts
    45,986

    Re: getting list of files in a directory into txt file

    Quote Originally Posted by JetVBAMan View Post
    oh come on, so rude, i'm what, under 10 posts in?
    ...Do you know how to read text files into Excel, perhaps I'll show you next time. Off to bed...
    Abuse, disrespect and impoliteness will not be tolerated on this forum - please refrain from this in future.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1