The code contains two functions. You need to run the MoveDirectory function pass it the source and destination directories. If copy is set to false the origional dir is removed. If it is set to true the origional dir is not deleted.
By : metcarob
function MoveDirectory($source,$dest,$copy=false) {
//remove trailing slashes
if (substr($dest,-1) == "\\") $dest = substr($dest,0,strlen($dest)-1);
if (substr($source,-1) == "\\") $source = substr($source,0,strlen($source)-1);
if (!file_exists($source)) return FALSE;
Ensure_Sub_Directory_Exists($dest);
//now copy all the files & direcrtories to the new location and deltet them
$d = opendir($source);
while ($f = readdir($d)) {
$l = $source . "\\" . $f;
if (is_dir($l)) {
if (!($f['value']=="." || $f=="..")) {
MoveDirectory($l,$dest . "\\" . $f,$copy);
};
} else {
copy( $l ,$dest . "\\" . $f);
if (!$copy) {
//we are moving the directory so we should delete the file
unlink($l);
};
};
};
closedir($d);
if (!$copy) {
rmdir($source);
};
return TRUE;
};
function Ensure_Sub_Directory_Exists($dir) {
//When passed a directory create it
if (substr($dir,-1) == "\\") $dir = substr($dir,0,strlen($dir)-1);
if (file_exists($dir)) return TRUE;
$a = explode("\\",$dir);
while ($t = each($a)) {
$b = $t['value'];
};
$b = str_replace("\\" . $b,"",$dir);
//does $b exist?
if (!file_exists($b)) {
Ensure_Sub_Directory_Exists($b);
};
//PArent exists so make this directork exist
mkdir($dir);
return TRUE;
};
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More File Manipulation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools. FREE! Go There Now!
|
|
|
|
Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. FREE! Go There Now!
|
|
|
|
In this five-part "Building a grid system using WS-Resource Transfer" series, we look at the use of WS-Resource Transfer (WS-RT) in different areas of the grid environment -- from using it as a method for storing and recovering general information about grid-to-grid monitoring and management, and security. We also examine how WS-RT can be used for the distribution and division of work. In any grid, there is a huge amount of metadata about the grid that needs to be stored and distributed. Using WS-RT makes sharing the information, especially the precise information required by different systems in the grid, significantly easier. Here in Part 4, we look at both sides of the security session, both in terms of using WS-RT as an aid to the authorization process and at combining WS-Security with WS-RT for secure resource exchange. FREE! Go There Now!
|
|
|
|
Set up a PHP Web interface for the Java(TM) business application using a database created in earlier in this series. The PHP Web interface collects information from users and sends the session data to the Java business application for processing and for a response. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
IBM DB2 9.5 provides new options for tighter security, and allows for more granularity and flexibility in administration of the database. This tutorial is the second of two tutorials that cover roles and trusted contexts. Follow the exercises in this tutorial, and learn how to take advantage of the new DB2 feature trusted contexts in combination with other essential e-business technologies such as Web services, Web application server, and DB2 database server. FREE! Go There Now!
|
|
|
|
Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code. FREE! Go There Now!
|
|
|
|
XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
|
|
|
|
Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |