1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with a simple batch file

Discussion in 'Windows - General discussion' started by klassic, Jan 10, 2008.

  1. klassic

    klassic Regular member

    Joined:
    Mar 4, 2004
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    26
    I set up a simple batch file in windows to create a file that lists the names of all files in a folder. I added it to the action list for folders so I can run this on any folder at any time. Here is the code from my batch file:

    Code:
    @echo off 
       dir %1 /-p /b /o:gn >File-List.txt
       exit
    Is there any way that I can add the folder name to the beginning of the created file name? IE if I run this on a folder "Downloads" the resulting file name would be "Downloads-File-List.txt"

    I use this forum for everything else, so I hope someone can help. Or if someone knows a better forum to post this type of question please let me know.
     
  2. omnicore

    omnicore Member

    Joined:
    Jan 7, 2008
    Messages:
    96
    Likes Received:
    0
    Trophy Points:
    16
    I'm no expert but I don't think it's possible to do what you want with a simple batch file, it'll probably require writing a vb script.
     
  3. varnull

    varnull Guest

    It's easy but I can't remember exactly how.. you need to get the directory name, and assign it to $dir_name.. then cd to the working directory, run your batchfile and output >$dir_name File-List.txt

    or have I got confused with C++ ?? It's been a really long time since I did and dos batchfile stuff... There are books and guides all over the place about dos batchfile functions.. I do know you don't need anything like visual basic to do this... because we were doing it long before there was such a thing.

     
  4. omnicore

    omnicore Member

    Joined:
    Jan 7, 2008
    Messages:
    96
    Likes Received:
    0
    Trophy Points:
    16
    The challenge though is that he added it to his "action menu" which I believe he means when he right clicks on a folder he wants to run it from there. Last I remembered there wasn't too much right clicking going on in DOS
     
  5. klassic

    klassic Regular member

    Joined:
    Mar 4, 2004
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    26
    I am trying to do this by just running the batch file. I am assuming that any dos commands would just need to be added to this .bat file. I only added it to the action menu to make it simpler.
     
  6. seb32

    seb32 Regular member

    Joined:
    Dec 31, 2005
    Messages:
    351
    Likes Received:
    0
    Trophy Points:
    26
  7. klassic

    klassic Regular member

    Joined:
    Mar 4, 2004
    Messages:
    152
    Likes Received:
    0
    Trophy Points:
    26
    Thanks seb32! That link and another tip on that site got me part of the way. I started tweaking some of the code they had and figured out that it was easier than I thought. All I had to do was replace File-List with %1 and it worked. Here is the new code.
    Code:
    @echo off 
       dir %1 /-p /b /o:gn >%1%.txt
       exit
    Now all I have to do is right click on a folder and use the action, "Create File List", that I created and I get a .txt file that lists all the files that are in that folder.

    Man, I love this site. Even if you don't get the exact answer you need someone is bound to get you close. Thanks again everyone who replied, and everyone who ever has helped someone on this site.
     

Share This Page