Sponsored Content
Top Forums Programming Perl - Moving file based upon filesize in folder Post 302897565 by spacebar on Monday 14th of April 2014 07:59:37 PM
Old 04-14-2014
Try this example:
Code:
use strict;
use warnings;
use File::Copy 'move';

my $dir           = 'C:/temp/';
my $TooBigOutput  = "${dir}TooBigOutput.txt";

open( my $TooBigOutput_fh, '>', $TooBigOutput ) or die "Can't open $TooBigOutput $!\n";

opendir( DIR, $dir ) or die "Can't open directory: $TooBigOutput $!\n";
while ( my $file = readdir( DIR ) ) {
  my $filesize = -s $file;
  if ( $filesize gt 0 ) {
    move( "$dir$file", "$dir/TooBig/$file" );
    print $TooBigOutput_fh "$dir$file $filesize";
  } else {
    move( "$dir$file", "$dir/TooSmall/$file" );
  }
}
closedir( DIR );
close $TooBigOutput_fh;

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

moving a file to a new folder and automated ftp

how to move a file to a different folder after an automated FTP . (1 Reply)
Discussion started by: dineshr85
1 Replies

2. Shell Programming and Scripting

shell script for moving all the file from the same folder

Hi , I need a shell script which basicaly moves all the files from one folder say folder x to folder y and once they are moved to folder y a datetimestamp should be attached to there name for ex file a should be moved to y folder and renamed as a_20081015 (1 Reply)
Discussion started by: viv1
1 Replies

3. UNIX for Dummies Questions & Answers

moving file from one folder to another

i have created file in one of the folders on unix UNIX 's36tou -T XYZ /tmp/p400/dataout/ias/AB >/dev/null I am using above command to copy file from one system to unix XYZ is name of file on my system usually this name is very big so i use -T to trim some charaters from name. noe... (1 Reply)
Discussion started by: ajit.yadav83
1 Replies

4. Shell Programming and Scripting

Moving 100K file to another folder using 1 command

Hi, I need to move 1000s of files from one folder to another. Actually there are 100K+ files. Source dir : source1 Target dir : target1 Now if try cp or mv commands I am getting an error message : Argument List too long. I tried to do it by the time the files are created in the source... (6 Replies)
Discussion started by: unx100
6 Replies

5. Shell Programming and Scripting

Need help in finding filesize , moving file , gzipping file

Hi , Please help with the following questions 1) how can i find size of a file ? i have written du -k $flname > s1 . Is this right ? Any other better suggeastions ? 2) how do I use mv command for moving the file ? I need the syntax with some examples 3) Command for printing the total... (1 Reply)
Discussion started by: Learning!
1 Replies

6. Shell Programming and Scripting

Shell Script for moving 3 days old file to Archive Folder

Hi Experts, I have a "Source" folder which may contain some files. I need a shell script which should move all files which are older than 3 days to "Archive" folder. Thanks in Advance... (4 Replies)
Discussion started by: phani333
4 Replies

7. Shell Programming and Scripting

Moving files based on file name

Hi All, I have multiple files in the folder, I want to move those files into the other folder on based of name File names: Template_server1_01==> Template_server1_02==>To one directory /Server1 Template_server1_03==> Template_server2_01==> Template_server2_02==>To one... (9 Replies)
Discussion started by: sharsour
9 Replies

8. Ubuntu

Shell Scripting , Moving Old file to specific folder

There are files stored like 14.Aug.2014.log, 15.Aug.2014.log etc. in a folder $HOME/logyou need to find out all the log files of last 1 month and move them into $HOME/logs/lastmonth/ this should be implemented with reference of file name. ---------- Post updated at 12:30 PM ----------... (3 Replies)
Discussion started by: shajoftaj
3 Replies

9. Homework & Coursework Questions

Shell Scripting , Moving Old file to specific folder

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: There are files stored like 14.Aug.2014.log, 15.Aug.2014.log etc. in a folder $HOME/log you need to find out all... (4 Replies)
Discussion started by: shajoftaj
4 Replies

10. Shell Programming and Scripting

Shell scripting for moving folder specific files into target directory of that country folder.

I need help to write shell script to copy files from one server to another server. Source Directory UAE(inside i have another folder Misc with files inside UAE folder).I have to copy this to another server UAE folder( Files should be copied to UAE folder and Misc files should be copied in target... (3 Replies)
Discussion started by: naresh2389
3 Replies
explain_closedir_or_die(3)				     Library Functions Manual					explain_closedir_or_die(3)

NAME
explain_closedir_or_die - close a directory and report errors SYNOPSIS
#include <libexplain/closedir.h> void explain_closedir_or_die(DIR *dir); DESCRIPTION
The explain_closedir_or_die function is used to call the closedir(3) system call. On failure an explanation will be printed to stderr, obtained from explain_closedir(3), and then the process terminates by calling exit(EXIT_FAILURE). This function is intended to be used in a fashion similar to the following example: explain_closedir_or_die(dir); dir The dir, exactly as to be passed to the closedir(3) system call. Returns: This function only returns on success. On failure, prints an explanation and exits. SEE ALSO
closedir(3) close a directory explain_closedir(3) explain closedir(3) errors exit(2) terminate the calling process COPYRIGHT
libexplain version 0.52 Copyright (C) 2008 Peter Miller explain_closedir_or_die(3)
All times are GMT -4. The time now is 09:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy