DOS / Batch question

Discussion in 'Web Design & Coding' started by Tosca, Nov 9, 2005.

  1. Tosca

    Tosca VIP Member

    Joined:
    Nov 8, 2004
    Messages:
    249
    Likes Received:
    3
    Location:
    Townville
    Hi everyone

    I have XP Pro SP2 and am not sure if this is the correct area for this question. Apologies if not and I hope that it can be moved to a more appropriate one.

    If I open the command screen, I can use something like <dir desktop.ini /as /s > C:\list.txt> to create a list of the desktop.ini files on the hard drive. Similarly, I can see what's in the desktop.ini using <type desktop.ini>.

    What I'd like to do is combine these commands to produce a text file comprising the complete filename (including directories) of the desktop.ini, followed by what's in the desktop.ini, then the complete filename of the next desktop.ini, then what's in it etc.

    I haven't been able to get it to work from the command screen so suspect that it may have to be a batch file to work through all of the desktop.ini files on the hard drive. I understand that "if .. then .." type of phrases can be used in Batch but what about something like "for each desktop.ini on the hard drive, type desktop.ini >> C:\list.txt"

    Thanks in advance
     
    Tosca, Nov 9, 2005
    #1
    1. Advertisements

  2. Tosca

    Cuddlez I'm Ron Burgundy? VIP Member

    Joined:
    Dec 21, 2004
    Messages:
    166
    Likes Received:
    6
    Location:
    O.C. Californi-ay
    Firstly, to print out to a file you only use a single > . So it would be
    Code:
    type desktop.ini > C:\filename.txt
    As far as how to do it, you should be able to do it using the for command. http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx


    Something like:
    Code:
    for %%f (desktop.ini) dir desktop.ini /as /s > C:\filename.txt
    That should do the first command and you ought to be able to combine the second command using an if. Like:
    Code:
    if dir desktop.ini /as /s EXISTS
    then for %%f (desktop.ini) dir desktop.ini /as /s 
    type desktop.ini > C:\filename.txt
    I hope that helps.
     
    Cuddlez, Nov 9, 2005
    #2
    1. Advertisements

  3. Tosca

    Tosca VIP Member

    Joined:
    Nov 8, 2004
    Messages:
    249
    Likes Received:
    3
    Location:
    Townville
    Thank you Cuddlez. I mentioned the double right chevron because I know that this appends to a file, rather than simply writes to the file. I'd have thought that, as the batch file cycles through the desktop.ini files, the information should be appended to the previous information.

    I've looked at your suggestion but can't get it to work - yet. I'll continue to work on it!
     
    Tosca, Nov 9, 2005
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.