search for a list of files

Discussion in 'macOS' started by sublevel4, Jun 16, 2017.

  1. sublevel4 macrumors newbie

    Joined:
    Feb 20, 2009
    #1
    I have a list of numbers, those number are in the names of the files i want to find. is there a way to search for each name on that list in a specific folder? Then is there a way to move them to another folder?
     
  2. BrianBaughn macrumors 601

    BrianBaughn

    Joined:
    Feb 13, 2011
    Location:
    Baltimore, Maryland
    #2
    I'm confused a bit by your terminology. I think the answer is simple and I could try to guess what you're asking but by "name" do you mean "filename"? What do you mean by "list"?
     
  3. Gregg2 macrumors 603

    Joined:
    May 22, 2008
    Location:
    Milwaukee, WI
    #3
    ????
    Multiple files
    Filenames are all numeric
    Located in different folders
    Want to find several files and move them to another folder

    If I've got that right, then, yeah: one at a time
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    A Smart Folder search can probably do this. You'd have to add the numbers from the list one at a time.

    https://support.apple.com/kb/PH25484?viewlocale=en_US&locale=en_US

    You can get more complex search criteria by holding down the OPTION key, the (+) button will change its label, then click it, and you then have an "Any"/"All" popup. If you know boolean logic, "Any" is OR, and "All is AND.

    https://support.apple.com/kb/PH25589?locale=en_US

    If a Smart Folder search isn't good enough, maybe look on the Mac App Store for apps that perform complex searches and file-finding actions.
     
  5. sublevel4 thread starter macrumors newbie

    Joined:
    Feb 20, 2009
    #5
    By list i mean an excel or txt file that has
    1234
    1235
    1236....

    I would like to take that file and search a specific directory and all of its sub directories for a file that has 1234 in the name. Then move through that list/file looking in the same directory for each number in that list. The list can contain over 300 lines. It would be nice to be able to do something with the file if it finds it like copy it. I guess i am going to have to find a way to script it. I have yet to find a search application that takes a file as input.
     
  6. KALLT macrumors 601

    Joined:
    Sep 23, 2008
    #6
    So you want to compare the entries in the text file to file names in a directory. You could use a simple chain of commands in Terminal, e.g.
    Code:
    find PATH | grep -f LIST.txt
    or:
    Code:
    while read file; do find PATH -name $file; done < LIST.txt
    Replace PATH with the directory and LIST.txt with your text file. The first one lists all files in the directory and prints those that are on the list, whereas the second will look for matching file names for each line in the file.

    This will not work with Excel though and it presupposes that each file name is on a separate line. You can also so pattern matching; there is a lot more you can do with Terminal commands.
     
  7. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    This idea can be taken further, by putting the entire process into an Automator workflow.

    For example, the Automator workflow can tell Excel to open a file and export a particular column as text (an AppleScript step), then the text file can be passed along to a Run Shell Script step that contains a script like you've shown. The output from that can be passed along to subsequent Automator steps. If the output of the Run Shell Script is a list of Posix-style pathnames, then that can be used as input for a Move or Duplicate step.

    In any case, the OP will need to post a more detailed description, and possibly provide sample data. At this point, it's a programming task, and although Automator offers a high-level view of such things, the individual steps will need shell scripting, with specific details filled in and then tested by the OP.

    I also suggest changing $file in the example script to "*$file*", as the request is for the number in the filename, not as the filename. However, I could be misinterpreting what the OP is asking for. Details are important in programming.
     

Share This Page