This repository was archived by the owner on Aug 14, 2022. It is now read-only.
File tree 6 files changed +75
-2
lines changed
6 files changed +75
-2
lines changed Original file line number Diff line number Diff line change 14
14
* Added ` File/_config.yml ` file.
15
15
* Added ` File/.travis.yml ` file.
16
16
17
+ * Added ` Josantonius\File\Test\FileTest::CopyDirRecursively() ` method.
18
+
17
19
* Deleted ` Josantonius\File\Tests\FileTest::testSearchString() ` method.
18
20
19
21
* Deleted ` Josantonius\File\Tests\FileTest ` class.
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ File::exists();
60
60
File::delete();
61
61
File::createDir();
62
62
File::deleteEmptyDir();
63
+ File::CopyDirRecursively();
63
64
File::deleteDirRecursively();
64
65
File::getFilesFromDir();
65
66
```
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ File::exists();
60
60
File::delete();
61
61
File::createDir();
62
62
File::deleteEmptyDir();
63
+ File::CopyDirRecursively();
63
64
File::deleteDirRecursively();
64
65
File::getFilesFromDir();
65
66
```
Original file line number Diff line number Diff line change @@ -87,6 +87,40 @@ public static function createDir($path) {
87
87
return (!is_dir ($ path ) && @mkdir ($ path , 0777 , true ));
88
88
}
89
89
90
+ /**
91
+ * Copy directory recursively.
92
+ *
93
+ * @since 1.1.4
94
+ *
95
+ * @param string $fromPath → path from copy
96
+ * @param string $toPath → path to copy
97
+ *
98
+ * @return boolean
99
+ */
100
+ public static function CopyDirRecursively ($ from , $ to ) {
101
+
102
+ if (!$ path = self ::getFilesFromDir ($ from )) { return false ; }
103
+
104
+ self ::createDir ($ to = rtrim ($ to , '/ ' ) . '/ ' );
105
+
106
+ foreach ($ path as $ file ) {
107
+
108
+ if ($ file ->isFile ()) {
109
+
110
+ if (!copy ($ file ->getRealPath (), $ to .$ file ->getFilename ())) {
111
+
112
+ return false ;
113
+ }
114
+
115
+ } else if (!$ file ->isDot () && $ file ->isDir ()) {
116
+
117
+ self ::CopyDirRecursively ($ file ->getRealPath (), $ to . $ path );
118
+ }
119
+ }
120
+
121
+ return true ;
122
+ }
123
+
90
124
/**
91
125
* Delete empty directory.
92
126
*
Original file line number Diff line number Diff line change @@ -174,22 +174,57 @@ public function testDeleteEmptyDirError() {
174
174
}
175
175
176
176
/**
177
- * Test delete directory recursively.
177
+ * Test copy directory recursively.
178
178
*
179
179
* @since 1.1.4
180
180
*
181
181
* @return void
182
182
*/
183
- public function testDeleteDirRecursively () {
183
+ public function testCopyDirRecursively () {
184
184
185
185
File::createDir (__DIR__ . '/test/test/test/ ' );
186
186
187
187
touch (__DIR__ . '/test/test/test/test.txt ' );
188
188
189
+ $ this ->assertTrue (
190
+
191
+ File::copyDirRecursively (__DIR__ . '/test/ ' , __DIR__ . '/copy/ ' )
192
+ );
193
+ }
194
+
195
+ /**
196
+ * Test copy missing directory recursively.
197
+ *
198
+ * @since 1.1.4
199
+ *
200
+ * @return void
201
+ */
202
+ public function testCopyMissingDirRecursively () {
203
+
204
+ $ this ->assertFalse (
205
+
206
+ File::deleteDirRecursively (__DIR__ . '/unknown/ ' )
207
+ );
208
+ }
209
+
210
+ /**
211
+ * Test delete directory recursively.
212
+ *
213
+ * @since 1.1.4
214
+ *
215
+ * @return void
216
+ */
217
+ public function testDeleteDirRecursively () {
218
+
189
219
$ this ->assertTrue (
190
220
191
221
File::deleteDirRecursively (__DIR__ . '/test/ ' )
192
222
);
223
+
224
+ $ this ->assertTrue (
225
+
226
+ File::deleteDirRecursively (__DIR__ . '/copy/ ' )
227
+ );
193
228
}
194
229
195
230
/**
You can’t perform that action at this time.
0 commit comments