/*
 * [NoSpace.java]
 *
 * Summary: Converts spaces in filenames to underscores.
 *
 * Copyright: (c) 2016-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2016-10-09 initial version
 */
package com.mindprod.example;

import com.mindprod.commandline.CommandLine;
import com.mindprod.filter.AllButSVNDirectoriesFilter;
import com.mindprod.filter.OnlyFilesFilter;

import java.io.File;

import static java.lang.System.*;

/**
 * Converts spaces in filenames to underscores.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2016-10-09 initial version
 * @since 2016-10-09
 */
public class NoSpace
    {
    /**
     * List directories and files on command line to correct.  -s mean recure dirs to right.
     *
     * @param args list of dirs and files
     */
    public static void main( String[] args )
        {
        final CommandLine commandLine = new CommandLine( args,
                new AllButSVNDirectoriesFilter(),
                new OnlyFilesFilter() );
        for ( File f : commandLine )
            {
            final String oldName = f.getName();
            final String newName = oldName.replace( ' ', '_' );
            if ( !newName.equals( oldName ) )
                {
                out.println( "renaming " + oldName + " to " + newName );
                if ( !f.renameTo( new File( newName ) ) )
                    {
                    out.println( "rename failed\n" );
                    }
                }
            }
        }
    }