VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/tests/utils/cp.js@ 85855

Last change on this file since 85855 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1const nsILocalFile = Components.interfaces.nsILocalFile;
2var prefix = "";
3
4function rename(source, newName)
5{
6 try {
7 var sourceFile = Components.classes["@mozilla.org/file/local;1"].
8 createInstance(nsILocalFile);
9 sourceFile.initWithPath(source);
10
11 }
12 catch (e) {
13 dump("Could not create nsILocalFile\n");
14 }
15
16
17 try {
18 sourceFile.copyTo(null, newName);
19 }
20 catch (e) {
21 dump("error coping" + e + "\n");
22 }
23}
24
25
26function cp(source, dest, followLinks, newName)
27{
28 try {
29 var sourceFile = Components.classes["@mozilla.org/file/local;1"].
30 createInstance(nsILocalFile);
31 sourceFile.initWithPath(source);
32
33 var destFile = Components.classes["@mozilla.org/file/local;1"].
34 createInstance(nsILocalFile);
35 destFile.initWithPath(dest);
36
37 }
38 catch (e) {
39 dump("Could not create nsILocalFile\n");
40 }
41
42 try {
43
44 if (! destFile.isDirectory())
45 {
46 dump("destination not a directory!\n");
47 return;
48 }
49 }
50 catch (e) {
51 dump("error accessing dest");
52 }
53
54 try {
55 if (followLinks)
56 {
57 sourceFile.copyToFollowingLinks(destFile, newName);
58 }
59 else
60 {
61 sourceFile.copyTo(destFile, newName);
62 }
63 }
64 catch (e) {
65 dump("error coping" + e + "\n");
66 }
67}
68
69
70function mv(source, dest, followLinks, newName)
71{
72 try {
73 var sourceFile = Components.classes["@mozilla.org/file/local;1"].
74 createInstance(nsILocalFile);
75 sourceFile.initWithPath(source);
76
77 var destFile = Components.classes["@mozilla.org/file/local;1"].
78 createInstance(nsILocalFile);
79 destFile.initWithPath(dest);
80
81 }
82 catch (e) {
83 dump("Could not create nsILocalFile\n");
84 }
85
86 try {
87
88 if (! destFile.isDirectory())
89 {
90 dump("destination not a directory!\n");
91 return;
92 }
93 }
94 catch (e) {
95 dump("error accessing dest");
96 }
97
98 try {
99 if (followLinks)
100 {
101 sourceFile.moveToFollowingLinks(destFile, newName);
102 }
103 else
104 {
105 sourceFile.moveTo(destFile, newName);
106 }
107 }
108 catch (e) {
109 dump("error coping" + e + "\n");
110 }
111}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette