@@ -73,13 +73,17 @@ export abstract class EntityBase<T extends EntityBaseAttribute> {
7373 public Move ( destDir :string ) :IotResult {
7474 let result :IotResult ;
7575 try {
76- //clear
77- if ( fs . existsSync ( destDir ) ) fs . emptyDirSync ( destDir ) ;
78- //mkdir
79- IoTHelper . MakeDirSync ( destDir ) ;
76+ //delete
77+ if ( fs . existsSync ( destDir ) )
78+ {
79+ fs . emptyDirSync ( destDir ) ;
80+ fs . removeSync ( destDir ) ;
81+ }
82+ //destDir - no need to create a folder
8083 fs . moveSync ( this . ParentDir , destDir ) ;
8184 //replace fields
82- this . _descFilePath = `${ destDir } \\${ this . ParentNameDir } ` ;
85+ const fileName = this . _descFilePath . substring ( this . ParentDir . length + 1 ) ;
86+ this . _descFilePath = path . join ( destDir , fileName ) ;
8387 result = new IotResult ( StatusResult . Ok , undefined , undefined ) ;
8488 } catch ( err : any ) {
8589 result = new IotResult ( StatusResult . Error , `Unable to move ${ this . _entityIntLabel } from folder ${ this . ParentDir } to folder ${ destDir } ` , err ) ;
@@ -88,6 +92,23 @@ export abstract class EntityBase<T extends EntityBaseAttribute> {
8892 return result ;
8993 }
9094
95+ public Remove ( ) :IotResult {
96+ let result :IotResult ;
97+ try {
98+ //delete
99+ if ( fs . existsSync ( this . ParentDir ) )
100+ {
101+ fs . emptyDirSync ( this . ParentDir ) ;
102+ fs . removeSync ( this . ParentDir ) ;
103+ }
104+ result = new IotResult ( StatusResult . Ok , `Folder has been deleted: ${ this . ParentDir } ` ) ;
105+ } catch ( err : any ) {
106+ result = new IotResult ( StatusResult . Error , `Unable to delete template folder: ${ this . ParentDir } ` , err ) ;
107+ }
108+ //result
109+ return result ;
110+ }
111+
91112 public Compare1 ( entityBase :EntityBase < T > ) :number {
92113 //0 - equal, 1 - entityBase up, -1 - entityBase down
93114 return this . Compare2 ( entityBase . Type , entityBase . Attributes . Version ) ;
0 commit comments