@@ -20,26 +20,27 @@ var path = require('path');
2020 * When multiple slashes are found, they're replaced by a single one;
2121*/
2222
23- console . log ( 'Given path: D:////Projects///NodeJS ///////TrainingKit' ) ;
24- console . log ( 'Apply normalize: ' + path . normalize ( 'D:////Projects///NodeJS ///////TrainingKit' ) ) ;
23+ console . log ( 'Given path: D:////Projects///Nodejs ///////TrainingKit' ) ;
24+ console . log ( 'Apply normalize: ' + path . normalize ( 'D:////Projects///Nodejs ///////TrainingKit' ) ) ;
2525
2626
27- console . log ( 'Given path: D:\\\Projects\NodeJS \\\\\\\\\\TrainingKit' ) ;
28- console . log ( 'Apply normalize: ' + path . normalize ( 'D:\\\Projects\NodeJS \\\\\\\\\\TrainingKit' ) ) ;
27+ console . log ( 'Given path: D:\\\Projects\Nodejs \\\\\\\\\\TrainingKit' ) ;
28+ console . log ( 'Apply normalize: ' + path . normalize ( 'D:\\\Projects\Nodejs \\\\\\\\\\TrainingKit' ) ) ;
2929
3030
31- console . log ( 'Given path: D:\\Projects\\NodeJS \\..\\Backbone' ) ;
32- console . log ( 'Apply normalize: ' + path . normalize ( 'D:\\Projects\\NodeJS \\..\\Backbone' ) ) ;
31+ console . log ( 'Given path: D:\\Projects\\Nodejs \\..\\Backbone' ) ;
32+ console . log ( 'Apply normalize: ' + path . normalize ( 'D:\\Projects\\Nodejs \\..\\Backbone' ) ) ;
3333
3434
35- console . log ( 'Given path: D:/Projects/NodeJS /../../Articles/Backbone' ) ;
36- console . log ( 'Apply normalize: ' + path . normalize ( 'D:/Projects/NodeJS /../../Articles/Backbone' ) ) ;
35+ console . log ( 'Given path: D:/Projects/Nodejs /../../Articles/Backbone' ) ;
36+ console . log ( 'Apply normalize: ' + path . normalize ( 'D:/Projects/Nodejs /../../Articles/Backbone' ) ) ;
3737
3838
3939/***
40- * Return directory name of a path.
40+ * Return directory name of a path.
41+ * Note: Nodejs is considered as file.
4142*/
42- console . log ( path . dirname ( 'D:/Projects/NodeJS ' ) ) ;
43+ console . log ( path . dirname ( 'D:/Projects/Nodejs ' ) ) ;
4344
4445
4546/***
@@ -57,40 +58,85 @@ console.log(path.extname('index'));
5758/***
5859 * Return the last portion of a path.
5960*/
60- console . log ( path . basename ( 'D:/Projects/NodeJS /index.html' ) ) ;
61+ console . log ( path . basename ( 'D:/Projects/Nodejs /index.html' ) ) ;
6162
62- console . log ( path . basename ( 'D:/Projects/NodeJS /index.html' , '.html' ) ) ;
63+ console . log ( path . basename ( 'D:/Projects/Nodejs /index.html' , '.html' ) ) ;
6364
6465/***
6566 * Return the relative path from `from` to `to`
6667*/
67- console . log ( path . relative ( 'D:/Projects/NodeJS' , 'D:/Projects/Backbone' ) ) ;
68+ console . log ( path . relative ( 'D:/Projects/Nodejs' , 'D:/Projects/Backbone' ) ) ;
69+
70+ console . log ( path . relative ( 'D:/Training/Nodejs' , 'D:/Projects/Backbone' ) ) ;
71+
72+ /***
73+ * Return the absolute path.
74+ * Note: need latest node.js version.
75+ */
76+ // console.log(path.isAbsolute('D:/Projects/Nodejs')); // true
77+ // console.log(path.isAbsolute('D:/Projects/Nodejs/os.html')); // false
78+ // console.log(path.isAbsolute('.')); // false
6879
69- console . log ( path . relative ( 'D:/Training/NodeJS' , 'D:/Projects/Backbone' ) ) ;
7080
7181/***
7282 * Resolves `to` to an absolute path.
83+ * It is as a sequence of cd commands in a shell.
7384*/
74- console . log ( path . resolve ( 'D:/Projects/NodeJS' , './Architecture' ) ) ;
85+ console . log ( path . resolve ( 'D:/Projects/Nodejs' , './Architecture' ) ) ;
86+
87+ console . log ( path . resolve ( 'D:/Projects/Nodejs' , 'D:/Projects/Backbone' ) ) ;
7588
76- console . log ( path . resolve ( 'D:/Projects/NodeJS ' , 'D:/Projects /Backbone' ) ) ;
89+ console . log ( path . resolve ( 'D:/Projects/Nodejs ' , '.. /Backbone' ) ) ;
7790
78- console . log ( path . resolve ( 'D:/Projects/NodeJS' , '../Backbone' ) ) ;
91+ console . log ( path . resolve ( 'D:/' , '/Projects' , 'Nodejs' , 'examples' ) ) ;
92+ console . log ( path . resolve ( 'D:/' , '/Projects' , '/Nodejs' , 'examples' ) ) ;
93+ console . log ( path . resolve ( 'D:/' , '/Projects' , '/Nodejs' , '/examples' ) ) ;
94+ console . log ( path . resolve ( 'D:/' , 'Projects' , 'Nodejs' , 'examples' ) ) ;
7995
8096/***
81- * Join the path.
97+ * Join all arguments and normalize the resulting path.
8298*/
83- console . log ( path . join ( 'D:/' , 'Projects' , 'NodeJS' ) ) ;
99+ console . log ( path . join ( 'D:/' , 'Projects' , 'Nodejs' ) ) ;
100+
101+ console . log ( path . join ( 'D:/' , 'Projects' , 'Nodejs' , '..' , 'Backbone' ) ) ;
84102
85- console . log ( path . join ( 'D:/' , 'Projects' , 'NodeJS' , '..' , 'Backbone' ) ) ;
103+ // Throws exception.
104+ // TypeError: Arguments to path.join must be strings.
105+ // console.log(path.join('D:/', {}, 'Projects'));
86106
87107/***
88108 * The [PLATFORM] specific file separator `\` or `/`.
89109*/
90- console . log ( 'D:/ Projects/NodeJS ' . split ( path . sep ) ) ;
110+ console . log ( 'Projects\\Nodejs\\examples ' . split ( path . sep ) ) ;
91111
92112/***
93113 * The [PLATFORM] specific path delimiter `:` or `;`.
94114*/
95115console . log ( process . env . PATH ) ;
96116console . log ( process . env . PATH . split ( path . delimiter ) ) ;
117+
118+ /***
119+ * Returns an object from a path string.
120+ * Note: need latest node.js version.
121+ * OUTPUT: {
122+ root : "C:\",
123+ dir : "C:\path\dir",
124+ base : "index.html",
125+ ext : ".html",
126+ name : "index"
127+ }
128+ */
129+ // console.log(path.parse('D:\\projects\\Nodejs\\examples\os.html'));
130+
131+ /***
132+ * Returns an path string from an object. the opposite of path.parse
133+ * Note: need latest node.js version.
134+ * OUTPUT: 'D:/projects/Nodejs/examples/os.html'
135+ */
136+ // path.format({
137+ // root: "D:/",
138+ // dir: "/projects/Nodejs/examples",
139+ // base: "os.html",
140+ // ext: ".html",
141+ // name: "os"
142+ // });
0 commit comments