473,382 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to move file from one directory to another directory in linux

Expand|Select|Wrap|Line Numbers
  1. @files = `ls /home/perl/`;
  2.  
  3. foreach $file (@files) {
  4.     print "$file";
  5.     $file_size = `du -h /home/perl/working/kiran/$file`;
  6.     if ( $file_size == 0 ) {
  7.         print "$file";
  8.         if(( $value = rename ("/home/perl/working/kiran/$file", "/home/perl/working/kalyan/$file")) == 0) {
  9.             print "success\n";
  10.         } else {
  11.             print "failure";
  12.         }
  13.         print "hello";
  14.     }
  15. }
  16.  
can any one correct this program
Jun 6 '07 #1
3 3625
jonathan184
154 100+
first you need to use open opendir command to open the dir

Then read the dir in the array
@array = readdir(DIR);

just to give you a start.


If you just want to run unix instead of perl comands

use the unxi commands like this

system "unix command";
Jun 6 '07 #2
miller
1,089 Expert 1GB
Greetings,

You really should be able to do something this simple rather easily if you just read the documentation for each function at:

http://perldoc.perl.org/

Nevertheless, here is ultimately what you're trying to acheive:

Expand|Select|Wrap|Line Numbers
  1. my $source = '/home/perl/working/kiran/';
  2. my $destination = '/home/perl/working/kalyan/';
  3.  
  4. opendir(DIR, $source) or die "can't open $source: $!";
  5.  
  6. foreach my $file (grep {! /^\.\.?$/} readdir(DIR)) {
  7.     if (-f "$source$file") {
  8.         print "$file";
  9.         rename("$source$file", "$destination$file") or die "Can't rename $file: $!";
  10.     }
  11. }
  12. closedir(DIR);
  13.  
- Miller
Jun 6 '07 #3
RonB
589 Expert Mod 512MB
Use the File::Path module - Create or remove directory trees
http://search.cpan.org/~dland/File-Path-2.08/Path.pm

I'm not sure what you mean by "disable the folder in source directory", especially since your question deals with moving the directory.
Dec 15 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: ken | last post by:
hello, i'm writing a c program on a linux system. i'm debugging a segmentation fault but i don't want it to dump a core file because the memory footprint of the program is over 300Mb and i don't...
2
by: Eje | last post by:
I have a webapplication on a server. One function is to build txt-files. These files should then be moved to a fixed directory on another computer in the company network. I have tried to use...
1
by: Matthew Eno | last post by:
I have a problem where I'm developing some code that moves files from one place to another (on the same drive) with the destination file having a new name. What's happening is that the line of...
5
by: Niron kag | last post by:
Hello! I want to move file from one directory to other. The exception is: “The process cannot access the file because it is being used by another process.” Maybe it is because I use this...
13
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them...
3
by: Arpan | last post by:
A Form has a FileUpload, 2 Buttons & a TextBox web server controls. Using the FileUpload control, I want to give users the provision to move & delete files that DO NOT exist in C:\Inetpub\wwwroot...
4
by: yan.python | last post by:
i have a question. when i run Interactive Interpreter in linux command promt,how can i move the cursor. for example,when i enter a string,i often enter the quotation mark "" first,and the move...
3
by: =?Utf-8?B?UHVyZSBIZWFydA==?= | last post by:
hi i need the code to move files from directory to another directory on sam local machine or to a network path, thank you. -- Ammar S. Mitoori IT Head QIMCO Co. Tel : +9744831199 Mobile :...
3
by: Paddy | last post by:
Hi, I am am falling at the first hurdle when trying to access a library using ctypes. I have a file libucdb.so which the file command says is shared object, but I cannot get it to load: Any...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.