Sponsored Content
Full Discussion: move file by year/mouth
Top Forums Shell Programming and Scripting move file by year/mouth Post 302227324 by mmm951 on Thursday 21st of August 2008 04:05:22 AM
Old 08-21-2008
I write script do this job.
any one has better advise!?

Code:
#!/bin/ksh
sdir=/tmp/mars
sedarg=s/[0-9][0-9]:[0-9][0-9]/`date +%Y`/g
mouth=0
while [ $mouth -le 11 ]
do
 mouth=`expr $mouth + 1`
 for yeardir in `ls -lt $sdir | sed -e $sedarg | grep ^- |awk '{print $8}' |uniq`
   do
	if [[ -d $sdir/$yeardir/$mouth ]] ;then
		echo $sdir/$yeardir/$mouth is exist
	else 
		mkdir -p $sdir/$yeardir/$mouth
		echo create $sdir/$yeardir/$mouth ok!!
	fi
   done
 done

#move file
ls -lt $sdir | sed -e $sedarg | grep ^- |awk '{print $6"\t"$8"\t"$NF}'  >$$.out
exec < $$.out
while read F_MOUTH F_YEAR FILE_NAME
do
  case "$F_MOUTH" in
        Jan) mv $sdir/$FILE_NAME $sdir/$F_YEAR/1;;
        Feb) mv $sdir/$FILE_NAME $sdir/$F_YEAR/2;;
        Mar) mv $sdir/$FILE_NAME $sdir/$F_YEAR/3;;
        Apr) mv $sdir/$FILE_NAME $sdir/$F_YEAR/4;;
        May) mv $sdir/$FILE_NAME $sdir/$F_YEAR/5;;
        Jun) mv $sdir/$FILE_NAME $sdir/$F_YEAR/6;;
        Jul) mv $sdir/$FILE_NAME $sdir/$F_YEAR/7;;
        Aug) mv $sdir/$FILE_NAME $sdir/$F_YEAR/8;;
        Sep) mv $sdir/$FILE_NAME $sdir/$F_YEAR/9;;
        Oct) mv $sdir/$FILE_NAME $sdir/$F_YEAR/10;;
        Nov) mv $sdir/$FILE_NAME $sdir/$F_YEAR/11;;
        Dec) mv $sdir/$FILE_NAME $sdir/$F_YEAR/12;;
  esac
done
rm $$.out


Last edited by mmm951; 08-21-2008 at 08:24 AM..
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do i get the year of the file

When i use, 'ls -ltr' I only see the month and day (timestamp) of the file. How do i see the year also. Thanks and Regards, Ram (1 Reply)
Discussion started by: ramky79
1 Replies

2. UNIX for Dummies Questions & Answers

Move files based on year

I have a directory which has crores of files since from 2003. I want to move only the 2003 files to another directory. Please help in doing this. Thanks (1 Reply)
Discussion started by: IHK
1 Replies

3. Shell Programming and Scripting

Move files based on year of creation

Hi All, I have a directory which has crores of files since from 2003 till now. I want to move only the 2003 files to another directory. Please help. Thanks (2 Replies)
Discussion started by: IHK
2 Replies

4. UNIX for Dummies Questions & Answers

Move files based on year

Hi All, I have a directory which has crores of files since from 2003. I want to move ony the 2003 files to another directory. Please help (9 Replies)
Discussion started by: IHK
9 Replies

5. UNIX for Dummies Questions & Answers

move all 2008 year's file to destination directory

I am trying to move file created/modified in 2008 year to <new directory>. But trapped badly in Xargs {}. Looks like mv is not getting destination file properly. It assumes source file s to be destination directory n gives me erroir. "Target must be a directory" Run- #/home/mktrisk: find... (4 Replies)
Discussion started by: kedar.mehta
4 Replies

6. Shell Programming and Scripting

File created year

Hi I need to get the File creation date (MM,DD,YYYY) using ls -ltr am getting only Month and Day only, I need year also when the file is modified. Thanks (3 Replies)
Discussion started by: KiranKumarKarre
3 Replies

7. Red Hat

Move files of a certain year to other directory

Hi all, I have a massive amount of recording files in .WAV format stored in a directory, files dating back to 2006. It is a huge amount of files as Linux cannot even do a listing of it all, it states: "argument list too long" What I would like to do is the following: Find all the files of... (6 Replies)
Discussion started by: codenjanod
6 Replies
QDateEdit(3qt)															    QDateEdit(3qt)

NAME
QDateEdit - Date editor SYNOPSIS
#include <qdatetimeedit.h> Inherits QDateTimeEditBase. Public Members QDateEdit ( QWidget * parent = 0, const char * name = 0 ) QDateEdit ( const QDate & date, QWidget * parent = 0, const char * name = 0 ) ~QDateEdit () enum Order { DMY, MDY, YMD, YDM } QDate date () const virtual void setOrder ( Order order ) Order order () const virtual void setAutoAdvance ( bool advance ) bool autoAdvance () const virtual void setMinValue ( const QDate & d ) QDate minValue () const virtual void setMaxValue ( const QDate & d ) QDate maxValue () const virtual void setRange ( const QDate & min, const QDate & max ) QString separator () const virtual void setSeparator ( const QString & s ) Public Slots virtual void setDate ( const QDate & date ) Signals void valueChanged ( const QDate & date ) Properties bool autoAdvance - whether the editor automatically advances to the next section QDate date - the editor's date value QDate maxValue - the editor's maximum value QDate minValue - the editor's minimum value Order order - the order in which the year, month and day appear Protected Members virtual QString sectionFormattedText ( int sec ) virtual void setYear ( int year ) virtual void setMonth ( int month ) virtual void setDay ( int day ) virtual void fix () Protected Slots void updateButtons () DESCRIPTION
The QDateEdit class provides a date editor. QDateEdit allows the user to edit dates by using the keyboard or the arrow keys to increase/decrease date values. The arrow keys can be used to move from section to section within the QDateEdit box. Dates appear in accordance with the local date/time settings or in year, month, day order if the system doesn't provide this information. It is recommended that the QDateEdit be initialised with a date, e.g. QDateEdit *dateEdit = new QDateEdit( QDate::currentDate(), this ); dateEdit->setRange( QDate::currentDate().addDays( -365 ), QDate::currentDate().addDays( 365 ) ); dateEdit->setOrder( QDateEdit::MDY ); dateEdit->setAutoAdvance( TRUE ); Here we've created a new QDateEdit object initialised with today's date and restricted the valid date range to today plus or minus 365 days. We've set the order to month, day, year. If the auto advance property is TRUE (as we've set it here) when the user completes a section of the date, e.g. enters two digits for the month, they are automatically taken to the next section. The maximum and minimum values for a date value in the date editor default to the maximum and minimum values for a QDate. You can change this by calling setMinValue(), setMaxValue() or setRange(). Terminology: A QDateEdit widget comprises three 'sections', one each for the year, month and day. You can change the separator character using QDateTimeEditor::setSeparator(), by default the separator will be taken from the systems settings. If that is not possible, it defaults to "-". <center> [Image Omitted] </center> See also QDate, QTimeEdit, QDateTimeEdit, Advanced Widgets, and Time and Date. Member Type Documentation QDateEdit::Order This enum defines the order in which the sections that comprise a date appear. QDateEdit::MDY - month-day-year QDateEdit::DMY - day-month-year QDateEdit::YMD - year-month-day (the default) QDateEdit::YDM - year-day-month (included for completeness; but should not be used) MEMBER FUNCTION DOCUMENTATION
QDateEdit::QDateEdit ( QWidget * parent = 0, const char * name = 0 ) Constructs an empty date editor which is a child of parent and called name name. QDateEdit::QDateEdit ( const QDate & date, QWidget * parent = 0, const char * name = 0 ) This is an overloaded member function, provided for convenience. It behaves essentially like the above function. Constructs a date editor with the initial value date, parent parent and called name. The date editor is initialized with date. QDateEdit::~QDateEdit () Destroys the object and frees any allocated resources. bool QDateEdit::autoAdvance () const Returns TRUE if the editor automatically advances to the next section; otherwise returns FALSE. See the "autoAdvance" property for details. QDate QDateEdit::date () const Returns the editor's date value. See the "date" property for details. void QDateEdit::fix () [virtual protected] Attempts to fix any invalid date entries. The rules applied are as follows: If the year has four digits it is left unchanged. If the year has two digits, the year will be changed to four digits in the range current year - 70 to current year + 29. If the year has three digits in the range 100..999, the current millennium, i.e. 2000, will be added giving a year in the range 2100..2999. If the day or month is 0 then it will be set to 1 or the minimum valid daymonth in the range. QDate QDateEdit::maxValue () const Returns the editor's maximum value. See the "maxValue" property for details. QDate QDateEdit::minValue () const Returns the editor's minimum value. See the "minValue" property for details. Order QDateEdit::order () const Returns the order in which the year, month and day appear. See the "order" property for details. QString QDateEdit::sectionFormattedText ( int sec ) [virtual protected] Returns the formatted number for section sec. This will correspond to either the year, month or day section, depending on the current display order. See also order. QString QDateEdit::separator () const Returns the editor's separator. void QDateEdit::setAutoAdvance ( bool advance ) [virtual] Sets whether the editor automatically advances to the next section to advance. See the "autoAdvance" property for details. void QDateEdit::setDate ( const QDate & date ) [virtual slot] Sets the editor's date value to date. See the "date" property for details. void QDateEdit::setDay ( int day ) [virtual protected] Sets the day to day, which must be a valid day. The function will ensure that the day set is valid for the month and year. void QDateEdit::setMaxValue ( const QDate & d ) [virtual] Sets the editor's maximum value to d. See the "maxValue" property for details. void QDateEdit::setMinValue ( const QDate & d ) [virtual] Sets the editor's minimum value to d. See the "minValue" property for details. void QDateEdit::setMonth ( int month ) [virtual protected] Sets the month to month, which must be a valid month, i.e. between 1 and 12. void QDateEdit::setOrder ( Order order ) [virtual] Sets the order in which the year, month and day appear to order. See the "order" property for details. void QDateEdit::setRange ( const QDate & min, const QDate & max ) [virtual] Sets the valid input range for the editor to be from min to max inclusive. If min is invalid no minimum date will be set. Similarly, if max is invalid no maximum date will be set. void QDateEdit::setSeparator ( const QString & s ) [virtual] Sets the separator to s. Note that currently only the first character of s is used. void QDateEdit::setYear ( int year ) [virtual protected] Sets the year to year, which must be a valid year. The range currently supported is from 1752 to 8000. See also QDate. void QDateEdit::updateButtons () [protected slot] Enables/disables the push buttons according to the min/max date for this widget. void QDateEdit::valueChanged ( const QDate & date ) [signal] This signal is emitted whenever the editor's value changes. The date parameter is the new value. Property Documentation bool autoAdvance This property holds whether the editor automatically advances to the next section. If autoAdvance is TRUE, the editor will automatically advance focus to the next date section if a user has completed a section. The default is FALSE. Set this property's value with setAutoAdvance() and get this property's value with autoAdvance(). QDate date This property holds the editor's date value. If the date property is not valid, the editor displays all zeroes and QDateEdit::date() will return an invalid date. It is strongly recommended that the editor is given a default date value (e.g. currentDate()). That way, attempts to set the date property to an invalid date will fail. When changing the date property, if the date is less than minValue(), or is greater than maxValue(), nothing happens. Set this property's value with setDate() and get this property's value with date(). QDate maxValue This property holds the editor's maximum value. Setting the maximum date value for the editor is equivalent to calling QDateEdit::setRange( minValue(), d ), where d is the maximum date. The default maximum date is 8000-12-31. See also minValue and setRange(). Set this property's value with setMaxValue() and get this property's value with maxValue(). QDate minValue This property holds the editor's minimum value. Setting the minimum date value is equivalent to calling QDateEdit::setRange( d, maxValue() ), where d is the minimum date. The default minimum date is 1752-09-14. See also maxValue and setRange(). Set this property's value with setMinValue() and get this property's value with minValue(). Order order This property holds the order in which the year, month and day appear. The default order is locale dependent. See also Order. Set this property's value with setOrder() and get this property's value with order(). SEE ALSO
http://doc.trolltech.com/qdateedit.html http://www.trolltech.com/faq/tech.html COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. AUTHOR
Generated automatically from the source code. BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qdateedit.3qt) and the Qt version (3.3.8). Trolltech AS 2 February 2007 QDateEdit(3qt)
All times are GMT -4. The time now is 09:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy