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

KingL
KingL Posts: 1,713 Forumite
Hi

I have long list of filenames in a .txt file. The files are distributed among (say) these folders:

Folder1\Subfolder1
Folder1\Subfolder2
Folder1\Subfolder3
Folder1\Subfolder4
Folder1\Subfolder5
Folder1\Subfolder6

I want to generate a list of the path statements for my listed files. (Those folders also contain plenty of _other_ files, but I am not interested in those and don't want them to appear on my list of path statements).

I can do this manually by doing a search in Folder 1 for each filename then "Copy as path" / paste each search result somewhere, but is there a more automated method available?

tia

Win 10.
«134

Comments

  • PasturesNew
    PasturesNew Posts: 70,698
    Part of the Furniture 10,000 Posts Name Dropper Photogenic
    Forumite
    Yes, using the dir function and /s to traverse the sub-directories, then piping the output results to a new .txt file.

    But the files have to be identifiable. e.g. if you knew those files and only those files contained a unique string, say they all contained the word ...FinalCopy... say.

    Is that enough info for you to go ahead and do it yourself? Or do you need the specific command?

    You'll be using:
    dir *FinalCopy*.*
    /s
    | (that's the pipe, bottom left of keyboard)
    YourEndTextFileName.txt
  • KingL
    KingL Posts: 1,713 Forumite
    they don't have any unique characteristic, (other than being in my list).

    Everything (wanted and unwanted) are .jpgs- does that make this approach a non-starter ?
  • WaywardDriver
    WaywardDriver Posts: 546
    Seventh Anniversary 500 Posts
    Forumite
    edited 2 August 2018 at 3:41PM
    Building on PasturesNew, at command prompt

    cd \Folder1
    dir *.* /s |all.txt

    import both all.txt and list of required files into Excel
    then use VLOOKUP to locate required files
    may need to create adjacent column with Folder1\SubFolderx\ removed from all files list
    assumes required filenames unique across all subfolders
  • D_M_E
    D_M_E Posts: 3,008
    1,000 Posts Fourth Anniversary Name Dropper
    Forumite
    edited 2 August 2018 at 2:50PM
    Can you use the edit facility to add a special character, such as @ to the start of every filename?

    If so, do that then use the search/replace facility to change the @ to

    dir Folder1\

    Then do another replace and change the .jpg at the end to /s/b >>newlist.txt

    That's if they are all jpg files.

    You should end up with a file called newlist.txt which should contain a list of files for example Folder1\subfolder1\file1.jpg and so on.

    The >> means create file newlist.txt and add every found file to it.

    Note that if the filenames have a space in somewhere, such as My File for example, you will need to put a " before Folder1 and after .jpg
  • Cornucopia
    Cornucopia Posts: 16,833
    Part of the Furniture 10,000 Posts Name Dropper Photogenic
    Forumite
    To create a list of just pathnames use this syntax:-

    CD \
    DIR *.jpg /s /b >allpaths.txt

    Then as suggested, load them into Excel, or one of the free Spreadsheets.

    Use VLOOKUP to compare the list of paths with the list of desired filenames.


    Alternatively, take a copy of your list of filenames, and save it with a ".BAT" suffix. Use an editor (Notepad, Wordpad) or a Spreadsheet to edit each filename into its own DIR command:-

    DIR filename1 /s /b >>allpaths.txt
    DIR filename2 /s /b >>allpaths.txt
    ...

    Then double-click this file in file explorer to run it. The file allpaths.txt will then contain a list of all matching pathnames.
  • that
    that Posts: 1,532 Forumite
    by the time you do all this above, freefilesync will probably have it all sorted and moved, just tick the boxes.

    Make sure you read the instructions before moving/deleting/copying.
  • googler
    googler Posts: 16,103
    Part of the Furniture 10,000 Posts Name Dropper Combo Breaker
    Forumite
    How many unique subfolders do you have?

    If it's a manageable number, could you simply search for subfolder name, then copy/paste the path from the address bar?
  • Cornucopia
    Cornucopia Posts: 16,833
    Part of the Furniture 10,000 Posts Name Dropper Photogenic
    Forumite
    that wrote: »
    by the time you do all this above, freefilesync will probably have it all sorted and moved, just tick the boxes.

    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.
  • psychic_teabag
    psychic_teabag Posts: 2,865
    Part of the Furniture 1,000 Posts Name Dropper Combo Breaker
    Forumite
    I'm confused... as far as I can tell, you already have a file containing the filenames you want to process, yet most of the responses seem to be using dir to generate a new list.

    What do you mean by a "path statement" ? My understanding was that the file you have is already a list of paths of the files you want.

    Perhaps the "for" command is of use to you - it can iterate over all the lines in a file, performing a command on each one. Specifically, the FOR/F variant.

    https://ss64.com/nt/for_f.html
    http://www.robvanderwoude.com/ntfor.php

    There are various ways to manipulate variables to extract just dir names, leaf names, etc.

    (Note also that piping | is for sending the output into another command, not sending to a file.)
  • (Note also that piping | is for sending the output into another command, not sending to a file.)
    Not being that familiar with DIR command, had assumed the suggested use of piping | was correct.
    Seems syntax is dir *.* > all.txt
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.