Languages

Menu
Sites
Language
Renaming File in file system

Hi,

 Could any one help in RENAMING file using file system.

 

Thanks in advance

Responses

11 Replies
Palitsyna

Hello,

Unfortunately, I haven't find such API. 

Probably you can create another file with required name and copy the contents of your file. I think it is not the best approach but I don't know any appropriate function.

Alex Dem

Hi,
I did not face such api for Web.
Alexey.

Alex Dem

also, for native apps you could try to use 'rename' method from <stdio.h>
Alexey.

Marco Buettner

Untest but maybe you can use

var file = null,
    location = 'documents';

function errorCB(err) {
    console.log( 'The following error occurred: ' +  err.name);
}

function successCB(path) {
    console.log('scanning is completed');
}

function onSuccess(dir) {
    file = dir.resolve("helloWorld.doc");
    file.name = "changedname.doc";
    // may you have to resolve before again with new name ;D
    tizen.content.scanFile(file.toURI(), successCB, errorCB);
}

tizen.filesystem.resolve(location, onSuccess, errorCB, 'rw'); 

 

Supreeth Kumar

Thanks Macro.. I'll check ...

Palitsyna

According to FileSystem API, the name attribute is readonly. So it do not work.
https://developer.tizen.org/dev-guide/2.3.1/org.tizen.web.apireference/html/device_api/mobile/tizen/filesystem.html#File

Marco Buettner

Yeah, I didnt check it before :( Than I will use moveTo or better copyTo and delete the old file.

Palitsyna

Yes, probably it is the only way in this situation.

Supreeth Kumar, try to use this functions:

void copyTo(DOMString originFilePath,
                DOMString destinationFilePath,
                boolean overwrite,
                optional SuccessCallback? onsuccess,
                optional ErrorCallback? onerror) raises(WebAPIException);

and

void deleteFile(DOMString filePath,
                    optional SuccessCallback? onsuccess,
                    optional ErrorCallback? onerror) raises(WebAPIException);

You sould add the following privilegehttp://tizen.org/privilege/filesystem.write

Examples of usage and API could be found here: https://developer.tizen.org/dev-guide/2.3.1/org.tizen.web.apireference/html/device_api/mobile/tizen/filesystem.html#File

Vikram

I think Marco's method should solve this issue. In spite of no rename api direct using but can assign new file name.

Do not forget add privilege <tizen:privilege name="http://tizen.org/privilege/filesystem.read"/> in config.xml

colin Rao

Hi,

I think the api "moveTo()" of file of filesystem can solve your problem. Check the usecase on the hlep doc by searching "filesystem".

void moveTo(DOMString originFilePath,
            DOMString destinationFilePath,
            boolean overwrite,
            optional SuccessCallback? onsuccess,
            optional ErrorCallback? onerror) raises(WebAPIException);

 

AVSukhov

Hello,

You can do bitwise copying using FileStream inerface to new created file, and after this delete original file.