LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2005, 10:00 AM   #1
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Rep: Reputation: 15
will this script copy only certain files?


i want to copy all the files [but none of the folders] from one folder to another.

To copy only the files and not the folders will this work:

Code:
<?php
//copy dep files
$dep = "/home/abc/dep/*";

$dep_new ="/home/xxx/mainwebsite/new";
copy ($dep, $dep_new);
?>

Last edited by verbatim; 04-27-2005 at 11:32 AM.
 
Old 04-27-2005, 10:31 AM   #2
mschutte
Member
 
Registered: Jan 2005
Location: Innsbruck, Austria
Distribution: Debian GNU/Linux Lenny
Posts: 68

Rep: Reputation: 15
The code looks like PHP, but if you had omitted the comment, it would be Perl... Please, mention the programming language you are using, so we do not have to guess. (Including the starters <?php and ?> would also help.)

Solution for PHP:
PHP Code:
define('TARGETDIR''/home/xxx/mainwebsite/new/');
foreach (
glob('/home/abc/dep/*') as $dep) {
    if (
is_file($dep))    # Exclude directories
        
copy($depTARGETDIR basename($dep));

Well, I haven't tested the code above.

Hope I could help,
mschutte
 
Old 04-27-2005, 01:00 PM   #3
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
thanks alot, it seems to work. Just one problem.

Code:
define('TARGETDIR', '/home/xxx/mainwebsite/new/'');
foreach (glob('/home/abc/dep/*') as $dep) {
    if (is_file($dep))    # Exclude directories
        copy($dep, TARGETDIR . basename($dep));
}
seems to work but i get the following error for every file that should be transfered [

Warning: copy(/home/abc/dep/*"misc_filename".php): failed to open stream: No such file or directory in /var/www/html/"scriptname".php): on line 101

line 101 :
Code:
  copy($dep, TARGETDIR . basename($dep));
any quick solutions??

Last edited by verbatim; 04-27-2005 at 01:26 PM.
 
Old 04-27-2005, 01:45 PM   #4
mschutte
Member
 
Registered: Jan 2005
Location: Innsbruck, Austria
Distribution: Debian GNU/Linux Lenny
Posts: 68

Rep: Reputation: 15
Well, it doesn't match the error message, but does the target directory exist? Oh, and does the httpd user have reading permissions to the source and target directories? The httpd user is commonly 'wwwrun', 'apache', ... depending on the distro.
It does work at my host.
 
Old 04-27-2005, 02:03 PM   #5
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
the target is made prior in the script, other folders are linked to the target folder, then i place your copy files script to copy the files.

so in theory it should work, but i cant get it for some reason.

Code:
// Define directory
$dir = "./new/{$username}/";

// make directory
if (!(is_dir($dir))) {
    if (mkdir($dir, 0755)) {
        echo "-";
      }
    else {
        echo ",";
      }}




//define symlink
$templates = "/home/misc/templates";
$html = "/home/misc/htmlarea";
$temc = "/home/misc/temp2";

$templates_new = "/home/xxx/mainwebsite/new/{$username}/templates";
symlink($templates, $templates_new);


$html_new = "/home/xxx/mainwebsite/new/{$username}/htmlarea";
symlink($html, $html_new);

$temc_new = "/home/xxx/mainwebsite/new/{$username}/temc";
symlink($temc, $temc_new);


}


define('TARGETDIR', '/home/xxx/mainwebsite/new/{$username}/'');
foreach (glob('/home/abc/dep/*') as $dep) {
    if (is_file($dep))    # Exclude directories
        copy($dep, TARGETDIR . basename($dep));
}

Last edited by verbatim; 04-27-2005 at 02:06 PM.
 
Old 04-28-2005, 09:28 AM   #6
mschutte
Member
 
Registered: Jan 2005
Location: Innsbruck, Austria
Distribution: Debian GNU/Linux Lenny
Posts: 68

Rep: Reputation: 15
It might be a typo, but you have to enclose the path in TARGETDIR in double quotes "" to expand {$username} -- in single quotes, {$username} is not substituted, but included verbatim.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need script to copy all files containing a certain string to a directory dc6463 Programming 21 04-18-2013 01:56 PM
Simple script to copy files, getting \r's at end of cmd ElricM Linux - Newbie 2 07-23-2005 11:21 AM
Foreach script to copy files gone wrong... clue? xiaodown Programming 2 11-02-2004 11:00 PM
How to copy in a script files to a samba folder? Julianus Linux - Networking 1 10-09-2004 07:29 PM
how to copy and paste between files and within files Bheki Linux - General 1 02-05-2002 05:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration