首页 \ 问答 \ 文件是否需要在C / C ++中使用open()打开扩展名?(Does a file need an extension to be opened with open() in C/C++?)

文件是否需要在C / C ++中使用open()打开扩展名?(Does a file need an extension to be opened with open() in C/C++?)

我正在编写一个使用Xcode for school的程序,需要我们使用open()系统调用。 我做
int input_file_desc = open(input_path, O_RDONLY);
printf("input file desc %d:\n", input_file_desc);

它提出-1。 文件的路径是〜/ data_to_read。 我在xcode中设置了命令行参数。 input_path是我从命令行获得的const char * 。 出于某种原因,如果我将文件名和命令行参数更改为〜/ data_to_read.txt,它可以正常工作。 如果需要更多信息,请与我们联系。 谢谢。

编辑:我只用.txt尝试它,看看是否是问题,但我仍然不知道为什么它首先需要扩展。 你可以拥有没有扩展名的文件吗? 在这种情况下它应该仍然有效,只要文件路径和参数都没有扩展名,对吧?


I'm writing a program using Xcode for school that requires we use the open() system call. I do
int input_file_desc = open(input_path, O_RDONLY);
printf("input file desc %d:\n", input_file_desc);

and it comes up with a -1. The file's path is ~/data_to_read. I set up the command line arguments in xcode. input_path is a const char * that i get from the command line. For some reason it works fine if I change the filename and command line argument to ~/data_to_read.txt. Let me know if more info is needed. thanks.

EDIT: I only tried it with .txt to see if that was the problem, but I still don't know why it needs an extension in the first place. You can have files without an extension right? In which case it should still work, as long as neither the file path nor the argument has an extension, right?


原文:https://stackoverflow.com/questions/8960297
更新时间:2022-02-19 11:02

最满意答案

你是对的。 您不能更改file输入字段的值。

请参阅动态设置文件输入的值


You are correct. You cannot change the value of a file input field.


Edit:

From 2017, you can set dropped files into a file input. See How to set file input value when dropping file on page?

相关问答

更多
  • 这是来自W3C的新的File API (与Mozilla有很多关系)。 我已经在其他的StackOverflow问题的答案中做了几个File API示例,这些问题可能很有用: 以文本和二进制形式读取HTML5文件API 在文件上传过程中使用Javascript获取图像尺寸 如何知道用JavaScript上传图片的大小? 第二个,特别是,显示加载一个本地图像文件到一个img元素,你可以随时使用一个canvas 。 如果你想拖放方面,你也可以看看HTML5 拖放的东西 ; 相关文章: Google将Gmail的 ...
  • 新答案: 在HTML5中,您可以添加multiple属性来选择多个文件。 老回答: 每个只能选择1个文件。 如果要发送多个文件,则必须使用多个输入标签或使用Flash或Silverlight。 New answer: In HTML5 you can add the multiple attribute to select more than 1 fi ...
  • 所选择的文件存储在数组中: [input].files 例如,您可以访问项目 // assuming there is a file input with the ID `my-input`... var files = document.getElementById("my-input").files; for (var i = 0; i < files.length; i++) { alert(files[i].name); } 对于jQuery舒适的人来说,同样容易 // assuming th ...
  • Android浏览器似乎不支持此功能: http://caniuse.com/#feat=input-file-multiple This feature seems not to be supported on Android Browsers: http://caniuse.com/#feat=input-file-multiple
  • 你需要它是不可能选择的吗? 然后使用HTML输入文件接受属性。 accept="image/png" 。 或者你希望它在用户选择之后从输入过滤掉? 然后,您应该使用自定义指令或在上传时检查ts代码中的文件类型。 在这种情况下编辑你的代码: onFileChange(event) { const fileList = event.target.files; console.log("User selected fileList:", fileList) Array.from(fileL ...
  • 假设我了解您的要求,请参阅这篇文章 。 这是一个JS修复,我认为这不会成为你使用AJAX的问题。 它允许你创建一个文件输入的样式,所以有了一点创意,你应该可以隐藏no file chosen文本。 Assuming I understand your requirements, see this article. It's a JS fix, which I suppose won't be a problem as you're using AJAX already. It allows you to s ...
  • 你是对的。 您不能更改file输入字段的值。 请参阅动态设置文件输入的值 You are correct. You cannot change the value of a file input field. Edit: From 2017, you can set dropped files into a file input. See How to set file input value when dropping file on page?
  • 您可以向页面添加普通input type="file"并将其设置为隐藏样式。 像这样的东西: (本示例仅使用内嵌样式,我建议将样式与标记分开。) 然后,您可以启动对其的单击以响应目标元素上的单击事件。 使用jQuery(假设您可以在li上设置id ,或者以某种方式在选择器中唯一地标识它),它将类似于: $('#clickableLiElement').click(function() ...
  • 最后,我发现了一种最好的方法。 虽然下降了,但我使用了: angular.element(document.querySelector('#upload_button')).on('change', handleFileSelect); 这个:
    Beleg per ...
  • 一般 - 没有办法! 此文件受到保护,在某些情况下,您可以获取文件名(而不是整个路径),但在某些浏览器中。 不可能通过html值属性或使用JS设置它。 Generally - NO WAY! This filed is protected and in some cases you can get the filename (not the whole path) but ... in some browsers. Not possile to set it via html value attribute ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)