We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

Generate a list of Path Statements for lots of scattered files

13

Comments

  • Cornucopia
    Cornucopia Posts: 16,833
    Part of the Furniture 10,000 Posts Name Dropper Photogenic
    Forumite
    edited 3 August 2018 at 3:32PM
    Just for anyone reading this thread who doesn't already know:-

    - The difference between ">file" and ">>file" is that the former directs output to a file, discarding any previous contents, and the latter appends output to the file.

    - The use of "(" and ")" around the FOR command in post # collects all of the output from each of the filenames it processes before placing it all in the output file, discarding any previous content. Without brackets, you would only get the output for the very last file in the list. However, I found that it has the side effect of listing all the DIR commands in the output, which may be undesirable.

    KingL wrote: »
    just a note - some of the file extensions are uppercase and some are lowercase. I would like to preserve the case. Does that make a difference ? - thanks

    The pathname includes the actual filename of the file, with case preserved, whilst the matching between the list and the files is case-insensitive.
  • psychic_teabag
    psychic_teabag Posts: 2,865
    Part of the Furniture 1,000 Posts Name Dropper Combo Breaker
    Forumite
    Cornucopia wrote: »
    However, I found that it has the side effect of listing all the DIR commands in the output, which may be undesirable.

    Ah, sorry, I forgot that bit... the interpreter echos commands by default. You can either set echo off, or you can use the @ prefix on a command to suppress that.

    for ... do @dir ...

    It's used in the examples at
    https://ss64.com/nt/for_f.html
    but I forgot the significance at the time.

    If you were putting it all in a bat script, you'd probably start with a
    @echo off
    at the top.
    https://ss64.com/nt/echo.html

    (I once spent a couple of days writing a scripting survival guide when I was forced to use windows for a while. I was pleasantly surprised that it had come quite a long way since the old days of dos, what with grouping commands, etc, but the syntax is somewhat clunky.)
  • that
    that Posts: 1,532 Forumite
    edited 4 August 2018 at 5:31AM
    Cornucopia wrote: »
    I think a proficient user of Excel will probably have this task done whilst the person installing software will still be puzzling over which download options to use. I'd certainly expect it to take no more than 5 minutes (if that).

    But each to their own.
    Yes, freefilesync does have a learning curve. You could be correct, but your proficiency might be different too others people. This is day no 3 and still he is still struggling.
  • KingL
    KingL Posts: 1,713 Forumite
    I already have and use FreeFileSynch, but I can't see how it would help, here. As I understand it, it would still require doing manual lookups to find the files in question. With a large number of files to look up, that would be too labour intensive.
    that wrote: »
    This is day no 3 and still he is still struggling.
    Not really. I was never intending to start working on it until the weekend, I just wanted to get the methodology established before then.

    thanks to all.

    So far: FOR /f "delims=" %G in (filelist.txt) DO @DIR /b /s %G >>fpaths.txt is working beautifully :)
  • KingL
    KingL Posts: 1,713 Forumite
    KingL wrote: »
    So far: FOR /f "delims=" %G in (filelist.txt) DO @DIR /b /s %G >>fpaths.txt is working beautifully :)

    I'm still getting good use out of this, but I have discovered that if there is a blank line (i.e. just a carriage return/end of paragraph character) in the middle of in filelist.txt, then the resultant fpaths.txt contains *everything* in the current directory, not just the files listed in filelist.txt.

    Is there a way to have it just ignore any blank lines in filelist.txt ?

    thanks a lot....
  • Can probably use an IF in the loop... something along the lines of

    for ... @if not [%g] == [] @dir/s ...

    See https://ss64.com/nt/if.html
  • KingL
    KingL Posts: 1,713 Forumite
    thanks, I'll have a play with that

    Also, while I'm here - I have found that if any of the files in the original list FILELIST.TXT are not found, the CLI reports "file not found", but doesn't say *which* file is not found. Is there a way of getting it to say which file the error relates to, so I can go and investigate manually ?

    thanks
  • A simple way...? There are far more elegant ways that will require a bit more batch coding but.........


    Change the batch text temporarily from

    FOR /f "delims=" %G in (filelist.txt) DO @DIR /b /s %G >>fpaths.txt
    to
    FOR /f "delims=" %G in (filelist.txt) DO @DIR /b /s %G>fpaths.txt
    ought to create a new file every time the redirected output goes to a file and thus (hopefully) the last located file path will be output. The file not located will be the next in your list?


    Could be that there is more than one file 'missing' so you may need to repeat if more are not located having deleted the missing ones from your file list?


  • KingL
    KingL Posts: 1,713 Forumite
    Hi , thanks but the job doesn't bomb-out when it hits a 'file not found', it still continues to the end, so removing one of the > s just gives me the path of the final (usually successful) file from filelist.txt, (rather than the full list of all the (successfully found) ones that I get with the >> method) ...
  • grumpycrab
    grumpycrab Posts: 5,045
    Part of the Furniture 1,000 Posts Name Dropper Bake Off Boss!
    Forumite
    Sorry to jump in - looks like you now know the difference between >> and >. Try a batch file fpaths.bat. With your normal FOR command with 2 differences.
    Replace %. With %%. And insert line1 as :-
    @echo on
    This should identify missing files.
This discussion has been closed.
★ ★ ★ Meet your Ambassadors

Categories

  • All Categories
  • 356K Banking & Borrowing
  • 255K Reduce Debt & Boost Income
  • 456.3K Spending & Discounts
  • 248.5K Work, Benefits & Business
  • 606.4K Mortgages, Homes & Bills
  • 179.1K Life & Family
  • 264.1K Travel & Transport
  • 1.6M Hobbies & Leisure
  • 16.2K Discuss & Feedback
  • 37.7K Read-Only Boards
Quick Search

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.