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

    Joined:
    Apr 6, 2006
    #1
    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

    Joined:
    Oct 22, 2007
    Location:
    An Island in the Salish Sea
    #2
    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

    Cinder6

    Joined:
    Jul 9, 2009
    #3
    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

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

    Code:
    # Specify which logfile to use
    LOGFILE="/path/to/logfile.log"
    
    # Remove existing logfile, if present
    rm -f ${LOGFILE}
    
    # Specify location to move files to
    ARCHIVEPATH="/path/to/archive"
    
    # 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}
    done
    
    To move them back you can use this code:
    Code:
    # Specify which logfile to use
    LOGFILE="/path/to/logfile.log"
    
    # Specify location to move files to
    ARCHIVEPATH="/path/to/archive"
    
    # 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}'`
       mv ${ARCHIVEPATH}/${FILE} ${ARCHIVEPATH}
    done < ${LOGFILE}
    
    If there any *.info files with the same name, do NOT use this script.
     

Share This Page