Any way to extract one type of file from numerous folders, and later put them back?

Discussion in 'macOS' started by marklight, Jul 22, 2009.

  1. marklight macrumors 6502

    Apr 6, 2006
    I have a type of file (.nfo) in numerous folders. I want to remove them and then later in time return them to their respective folders. I know I can use spotlight to find and either copy, move, or delete these files... but is there an easy way to later in time, return them to their respective folders... we're talking like over a thousand files here, each in separate folders that need to be taken out and later put back in, so manual labor isn't going to cut it...
  2. snberk103 macrumors 603

    Oct 22, 2007
    An Island in the Salish Sea
    Do you actually need to "move" them, or do just need to find them and work on the files easily? If you don't actually need to move them, then perhaps a "smart folder" may be the ticket? Sorry, but I don't know your Mac Savy-ness, so perhaps you know what a smart folder and have already determined its not the right solution. But....

    If you don't know what a smart folder is, then... it is a folder that has a search function built in, and updates itself in real time. Inside the folder are aliases (shortcuts) to all the items that fit the search criteria. You can open the files from the smart folder, do whatever you need to do, and then "save" the file and it will be saved in-situ. The file never actually moves, the smart folder merely "points" at the existing files.

    If that isn't what you need, then perhaps an automator script could help. I'm not a programmer - keep that in mind - but I might be tempted to duplicate your folder structure with a set of empty folders, but nested in a "Working" top folder. Then copy the files from their existing locations into the duplicated folders (by copying you have a back up version). As you work on the files you would then save them back into the duplicate folders. When you were done, then you could then reverse the copying process. Hope this helps. Again, if have already considered and rejected this... well then its beyond any help I can offer.
  3. Cinder6 macrumors 6502


    Jul 9, 2009
    It's trivial to move them all into one central location, but moving them back is harder, and more involved; you need some way of storing their original location, so you can put them back there. I also recommend Smart Folders. If you hate doing that, my next recommendation would be to create hard links of all the files.
  4. belvdr macrumors 603

    Aug 15, 2005
    Not tested, but this shell script should work:

    # Specify which logfile to use
    # Remove existing logfile, if present
    rm -f ${LOGFILE}
    # Specify location to move files to
    # Make sure ARCHIVEPATH exists
    mkdir -p ${ARCHIVEPATH}
    # Find all files with the extension .info
    for FILE in `find /path/to/files -type f -name "*.info"`; do
       FILENAME=`basename ${FILE}`
       FILEPATH=`dirname ${FILE}`
       echo "${FILEPATH},${FILENAME}" >> ${LOGFILE}
       mv ${FILE} ${ARCHIVEPATH}
    To move them back you can use this code:
    # Specify which logfile to use
    # Specify location to move files to
    # Find all files with the extension .info
    while read LINE; do
       FILENAME=`echo ${LINE} | awk -F '{print $2}'`
       FILEPATH=`echo ${LINE} | awk -F '{print $1}'`
    done < ${LOGFILE}
    If there any *.info files with the same name, do NOT use this script.

Share This Page