Re: create directories based on directory contents



gmail@xxxxxxxxxxxxxxxx wrote:
Suppose I have the following directory structure:

photos
|-AAA_100.jpg
|-AAA_101.jpg
|-AAA_102.jpg
|-XXXXX_100.jpg
|-XXXXX_101.jpg
|-XXXXX_100.jpg
|-ZZ_100.jpg
|-ZZ_101.jpg

is it possible to issue some commands that will automatically create 3 subdirectories, AAA, XXXXX, ZZ and subsequently move all the files into these folders?

Perhaps something like:

for i in *_*; do mkdir `echo $i | sed s/_*.//`; done
for i in *_*; do mv $i `echo $i | sed s/_*.//`; done

Untested, and probably not the most efficient, but might give you some ideas.


--
Milan Babuskov
http://njam.sourceforge.net
.



Relevant Pages

  • Re: create directories based on directory contents
    ... is it possible to issue some commands that will automatically create 3 ... subdirectories, AAA, XXXXX, ZZ and subsequently move all the files ... mkdir "$i" ...
    (comp.os.linux.misc)
  • Need help on Sun Fire V210 an Urgent!!!
    ... My company purchased 2 new Sun Fire V210 servers and I've to configure these systems and I've to ... install Solaris 9 OS. ... Please let me know the commands to configure/enable ports, ipaddress for these box and how to ... Add photos, events, holidays, whatever. ...
    (SunManagers)
  • Re: Suppressing Start-Up Messages
    ... ...but it gave an error message. ... I think that it's impossible to execute many commands at once with /C or /K. ... files in subdirectories with the "Archive" bit set. ...
    (comp.os.msdos.4dos)
  • Re: [opensuse] Digital Camera support
    ... I use a similar scheme that worked out very nicely for me - purely using the ... viewing or to look up photos. ... subdirectories so I can easily burn them on DVD; ... All cameras from all vendors wrap their image counter around after 9999: ...
    (SuSE)
  • Re: Renumbering sequence of filenames?
    ... its filename sequence back to zero, so although my library of photos had incremented up to the filename IMG_1432.JPG, I suddenly find myself with a new set of photos starting back at IMG_0001.JPG again. ... I'm sure there must be a way using old MS-DOS commands in the XP command window - but how? ... The Batch rename feature allows you to set the rename options to start renaming at whatever number you want choose. ...
    (rec.photo.digital)