与cordova的特定文件夹中的子文件夹

时间:2017-02-05 18:36:05

标签: cordova directory subdirectory

我有这个功能:

while(Comm_Loop)
{
    while (TCP_Loop)
    {   
        TCP_Client = accept(TCP_Server, (struct sockaddr*) &Client_Address, &Client_Address_Length) ;
        if ( TCP_Client != INVALID_SOCKET)
        {                   
            if (Data_Trans) 
            {
                State = send(TCP_Client, Msg, sizeof(Msg), 0) ;
                if (State != SOCKET_ERROR)
                    TCP_Loop = 0 ;
                else 
                    cout << Message[8] ;
            }
        }
        else cout << Message[10] ;
    }
    Check_Send = sendto(UDP_Socket,
                        UDP_Send_Packet,
                        sizeof(UDP_Send_Packet),
                        0,
                        (LPSOCKADDR) &Socket_Address, 
                        sizeof(Socket_Address));

        fd_set  SockSet  ;  
        timeval Time_Out ; 

        FD_ZERO(&SockSet) ;        
        FD_SET(UDP_Socket, &SockSet);  

        Time_Out.tv_sec  = 5;  
        Time_Out.tv_usec = 0 ;  

        State = select(0, &SockSet, (fd_set *)NULL, (fd_set *)NULL, &Time_Out) ;

        if((State > 0) && (FD_ISSET(UDP_Socket, &SockSet) != 0)) 
        { 
            Check_Recieve = recvfrom(UDP_Socket,
                                    UDP_Recieve_Packet,
                                    Buffer_Length,
                                    0,
                                    NULL,
                                    NULL);
            TCP_Loop = 1 ;
        }
        else 
        { 
            // Reception timeout
            Comm_Loop = 0; 
        }
    }

    closesocket(TCP_Client) ;
    closesocket(TCP_Server) ;
    closesocket(UDP_Socket) ;

     WSACleanup() ;

     return 0;
     }

我打电话

function createFolder(toDir, folderName, cb) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
    function (fileSystem) {
        var entry = fileSystem.root;
        entry.getDirectory(folderName, {
            create: true,
            exclusive: false
        }, cb(), () => {});
    }, () => {});  
}

但它不起作用。

此外,在params我插入toDir但我不知道如何使用它来指定创建子文件夹folderName的目录。 我不想总是使用fileSystem.root。

1 个答案:

答案 0 :(得分:1)

我解决了这个问题:

createFolder = function (toDir, folderName, cb) {
window.resolveLocalFileSystemURL(toDir, function (dirEntry) {
    function success(parent) {
        cb();
    }

    function fail(error) {
        alert("Unable to create new directory: " + error.code);
    }

    dirEntry.getDirectory(folderName, {
        create: true,
        exclusive: false
    }, success, fail);
});
}