文件系统管理本地文件夹和用户文件

时间:2018-02-05 09:46:31

标签: javascript angularjs node.js filesystems mean-stack

我有一个由mean-stack构建的网站。我使用File System在服务器中创建文件夹和写入文件。例如,在后端,我有:

localhost

现在,我想在本地用户磁盘中创建文件夹。例如,当我在app.config(['$stateProvider', function ($stateProvider) { $stateProvider .state('fileSystem', { url: '/fileSystem', template: `hallo`, controller: 'FileSystemCtrl' }) }]) app.controller('FileSystemCtrl', ['$scope', '$http', function ($scope, $http) { // var dir = "public/tmp/ABC" // creates well a folder under the folder of the project var dir = "file:///USers/SoftTimur/theProject/public/tmp/DEF" $http.post('/httpOnly/mkdir', { dir: dir }) .then(function () { console.log("done") }) }]) (Mac)中启动网站时,我希望它能够在我的Mac中创建一个文件夹。我试着在前端跟踪代码:

var dir = "file:///USers/SoftTimur/theProject/public/tmp/DEF"

我希望,{ Error: ENOENT: no such file or directory, mkdir 'file:///USers/SoftTimur/theProject/public/tmp/DEF' errno: -2, code: 'ENOENT', syscall: 'mkdir', path: 'file:///USers/SoftTimur/theProject/public/tmp/DEF' } 可以在我的Mac上创建一个文件夹,但失败并显示错误:

close()

有人怎么办?

1 个答案:

答案 0 :(得分:0)

以下代码有效。发布json数据

  

{" dir":" / USers / softTimur / theProject / public / tmp / DEF"}

我正在使用带有此库的密码提示的sudo命令 public static String makeScreen(View view) throws Exception { String filename = "file.png"; view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap b = view.getDrawingCache(); FileOutputStream file = null; try { file = new FileOutputStream(Environment.getExternalStorageDirectory().toString() + "folder/" + filename); if (file != null) { b.compress(Bitmap.CompressFormat.PNG, 98, file); file.close(); } view.destroyDrawingCache(); } catch (Exception e) { view.destroyDrawingCache(); } }

https://www.npmjs.com/package/sudo

mkdir -p dirname