[kwlug-disc] Need some advice/assistance on a script

Khalid Baheyeldin kb at 2bits.com
Tue Jun 18 12:53:01 EDT 2013


This should take care of the spaces.

cd /your_directory

# Iterate through files
for FILE in `find . -type f`
do
  # Don't move the file if it is already in the root directory
  if [ `dirname $FILE` != '.' ]; then
    mv "$FILE" .
  fi
done

# Remove the directories
for DIR in `find . -type d`
do
  if [ `dirname $FILE` != '.' ]; then
    rm -rf "$DIR"
  fi
done

On Tue, Jun 18, 2013 at 12:47 PM, R. Brent Clements <rbclemen at gmail.com>wrote:

> Khalid:  As near as I can tell your script is not dealing with spaces in
> directory names properly.
> I am getting "mv: cannot stat `Show/SFG033-07': No such file or directory"
> when the file is actually "SFG033-07 - Little Shop Of Horrors - Skid
> Row.cdg" in the directory "SFGD033 - Little Shop Of Horrors & The Rocky
> Horror Show".
>
> Brent
>
>
> On Tue, Jun 18, 2013 at 12:15 PM, Khalid Baheyeldin <kb at 2bits.com> wrote:
>
>> cd /your_directory
>>
>> # Iterate through files
>> for FILE in `find . -type f`
>> do
>>   # Don't move the file if it is already in the root directory
>>   if [ `dirname $FILE` != '.' ]; then
>>     mv $FILE .
>>   fi
>> done
>>
>> # Remove the directories
>> for DIR in `find . -type d`
>> do
>>   if [ `dirname $FILE` != '.' ]; then
>>     rm -rf $DIR
>>   fi
>> done
>>
>> On Tue, Jun 18, 2013 at 11:55 AM, R. Brent Clements <rbclemen at gmail.com>wrote:
>>
>>> I need to do something dramatically destructive.  I want to take a large
>>> directory tree of folders, and collapse them all down to their root
>>> folder.  File collisions are irrelevant.  How would you guys do this?
>>> (assume for the moment that you would).
>>>
>>> _______________________________________________
>>> kwlug-disc mailing list
>>> kwlug-disc at kwlug.org
>>> http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
>>>
>>>
>>
>>
>> --
>> Khalid M. Baheyeldin
>> 2bits.com, Inc.
>> Fast Reliable Drupal
>> Drupal optimization, development, customization and consulting.
>> Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra
>> Simplicity is the ultimate sophistication. --   Leonardo da Vinci
>> For every complex problem, there is an answer that is clear, simple, and
>> wrong." -- H.L. Mencken
>>
>> _______________________________________________
>> kwlug-disc mailing list
>> kwlug-disc at kwlug.org
>> http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
>>
>>
>
> _______________________________________________
> kwlug-disc mailing list
> kwlug-disc at kwlug.org
> http://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org
>
>


-- 
Khalid M. Baheyeldin
2bits.com, Inc.
Fast Reliable Drupal
Drupal optimization, development, customization and consulting.
Simplicity is prerequisite for reliability. --  Edsger W.Dijkstra
Simplicity is the ultimate sophistication. --   Leonardo da Vinci
For every complex problem, there is an answer that is clear, simple, and
wrong." -- H.L. Mencken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20130618/f3854aee/attachment.html>


More information about the kwlug-disc mailing list