createfile

CreateFile CREATE_NEW equivalent on linux

若如初见. 提交于 2019-12-01 06:14:52
问题 I wrote a method which tries to create a file. However I set the flag CREATE_NEW so it can only create it when it doesnt exist. It looks like this: for (;;) { handle_ = CreateFileA(filePath.c_str(), 0, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_HIDDEN | FILE_FLAG_DELETE_ON_CLOSE, NULL); if (handle_ != INVALID_HANDLE_VALUE) break; boost::this_thread::sleep(boost::posix_time::millisec(10)); } This works as it should. Now I want to port it to linux and and of course the CreateFile function are only for

一个极简的分布式文件系统

£可爱£侵袭症+ 提交于 2019-12-01 05:33:34
前言 开源的分布式存储系统比较多,比较有名的有:Ceph、GlusterFS、HDFS、TFS等。这些系统都比较复杂,代码动则几十上百万行,这些系统对初学者来说门槛比较高,特别是对于从事非分布式存储行业,但又想跨行学习分布式的同学来说,往往有这想法,但是不知道怎么入手。本文介绍之前实现的一个C++极简版的分布式文件系统 https://github.com/goyas/goya-fs , 代码只有一两百行,当然功能也很粗糙,只实现了简单的mkdir和ls这两条命令,但就像刚刚描述的,目的是学习,也便于大家对分布式有体感之后,方便阅读其他庞大的分布式存储系统,当然以后有空时间也会不断完善功能。 对于嵌入式,或者主要是从事单机开发的程序员来说,没接触分布式之前,都会感觉很神秘,往往会被高并发、海量数据分析处理等名词唬住。其实,职位没有智商之分,区别也就在于你有没有亲自动手摸过这些玩意儿。以往的经验告诉我,就算不会的东西,一个版本的时间,只要你稍微努点力基本就会达到行业的基本水平,当然越往上走就要看自己的兴趣和时间投入了。 好了,言归正传,下面开始介绍这个简单的分布式文件系统,选用的基础组件是leveldb + goyas-rpc,leveldb作为存储底座,goyas-rpc作为进程之间通信使用。有关leveldb的介绍网上非常多,这里就不再骜述,goyas-rpc可以参考之前的

Windows API的CreateFile()中的OPEN_ALWAYS和CREATE_ALWAYS之间的差异

ⅰ亾dé卋堺 提交于 2019-12-01 04:56:27
转自: http://www.voidcn.com/article/p-uzrihrua-bte.html 任何人都可以解释Windows API的 CreateFile() 功能的创建配置OPEN_ALWAYS和CREATE_ALWAYS之间的区别? 对我来说,似乎他们只是简单地“创建文件,如果它不存在”。 如果文件已经存在,CREATE_ALWAYS也会截断内容。另一方面,OPEN_ALWAYS不会破坏已经存在的文件。 以下是表格形式中不同值的工作原理: | When the file... This argument: | Exists Does not exist -------------------------+------------------------------------------------------ CREATE_ALWAYS | Truncates Creates CREATE_NEW +-----------+ Fails Creates OPEN_ALWAYS ===| does this |===> Opens Creates OPEN_EXISTING +-----------+ Opens Fails TRUNCATE_EXISTING | Truncates Fails 来源: https://www.cnblogs.com

Reopening serial port fails if not closed properly with CloseHandle

▼魔方 西西 提交于 2019-11-30 16:10:12
问题 I am working with USB device on Windows that is seen as a virtual serial port. I can communicate with the device using CreateFile and ReadFile functions, but in some cases my application does not call CloseHandle (when my application in development crashes). After that all calls to CreateFile fail (ERROR_ACCESS_DENIED), and the only solution is to log in to my computer again. Is there any way to force closing the open handle (or reopening) programmatically? 回答1: This is certainly not normal.

Create Text file from String using JS and html5

拈花ヽ惹草 提交于 2019-11-30 05:12:41
i want to create a text file from a string. currently i am using a function which takes an array and makes it into a string then using that string i want to create a local text file the user downloads. i have tried using this method function createFile(){ //creates a file using the fileLIST list var output= 'Name \t Status\n'+ fileLIST[0][0].name+'\t'+fileLIST[0][1]+'\n'; var Previous = fileLIST[0]; for (var i=1; i<fileLIST.length; i++) if (fileLIST[i][1] =='none' || fileLIST[i][1] == Previous[1]) continue else { Previous = fileLIST[i] output = output + fileLIST[i][0].name +'\t'+fileLIST[i][1]

Why is an extra file being created in FOR loop of batch program?

烂漫一生 提交于 2019-11-29 11:52:42
I've written the following batch file to create multiple files using FOR loop: @echo off cls FOR /L %%i IN (1 1 10) DO ( echo.> file%%i.txt IF ERRORLEVEL 0 echo Successfully created file 'file%%i.txt'. ) dir /b *.txt FOR %%i IN (*.txt) DO ( echo.> file%%i.txt IF ERRORLEVEL 0 echo Successfully created file 'file%%i.txt'. ) Here, 10 files (viz. file1.txt .... file10.txt ) are created in the first FOR loop. And in the second FOR loop I've used these files to frame the name of next new files. (viz. filefile1.txt.txt ... filefile10.txt.txt ) But, an extra file is being created : filefilefile1.txt

How to create empty folder in java? [duplicate]

99封情书 提交于 2019-11-28 16:01:42
Possible Duplicate: How to create a folder? I tried to use the File class to create an empty file in a directory like "C:/Temp/Emptyfile". However, when I do that, it shows me an error : "already made folder Temp". Otherwise, it won't create one for me. So, how do I literally create folders with java API? sarnold Looks file you use the .mkdirs() method on a File object: http://www.roseindia.net/java/beginners/java-create-directory.shtml // Create a directory; all non-existent ancestor directories are // automatically created success = (new File("../potentially/long/pathname/without/all/dirs"))

c++的CreateFile导致内存不能为written错误

跟風遠走 提交于 2019-11-28 14:40:47
LPCWSTR szFileName; szFileName=argv[2]; //LPCWSTR szFileName=L"test.txt";//文件名字可以根据自己的需要修改,或者用变量输入 HANDLE hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); // 共享方式打开,避免其他地方需要读写此文件 if (INVALID_HANDLE_VALUE != hFile) { DWORD dwFileSize = GetFileSize(hFile, NULL); PBYTE pBuffer = (PBYTE)malloc(dwFileSize + 2); int iLen = 0; if (!ReadFile(hFile, pBuffer, dwFileSize, &dwFileSize, NULL)) { free(pBuffer); return FALSE; } //CloseHandle(hFile); pBuffer[dwFileSize] = '\0'; pBuffer[dwFileSize + 1] = '\0'

python图片二值化提高识别率

血红的双手。 提交于 2019-11-28 08:47:51
   import cv2 from PIL import Image from pytesseract import pytesseract from PIL import ImageEnhance import re import string def createFile(filePath,newFilePath): img = Image.open(filePath) # 模式L”为灰色图像,它的每个像素用8个bit表示,0表示黑,255表示白,其他数字表示不同的灰度。 Img = img.convert('L') Img.save(newFilePath) # 自定义灰度界限,大于这个值为黑色,小于这个值为白色 threshold = 200 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) # 图片二值化 photo = Img.point(table, '1') photo.save(newFilePath) if __name__ == '__main__': createFile(r'1.bmp',r'newTest.png') 原图: 处理过后的图: 识别结果: 来源: https://www.cnblogs.com

Why is an extra file being created in FOR loop of batch program?

孤街浪徒 提交于 2019-11-28 05:49:38
问题 I've written the following batch file to create multiple files using FOR loop: @echo off cls FOR /L %%i IN (1 1 10) DO ( echo.> file%%i.txt IF ERRORLEVEL 0 echo Successfully created file 'file%%i.txt'. ) dir /b *.txt FOR %%i IN (*.txt) DO ( echo.> file%%i.txt IF ERRORLEVEL 0 echo Successfully created file 'file%%i.txt'. ) Here, 10 files (viz. file1.txt .... file10.txt ) are created in the first FOR loop. And in the second FOR loop I've used these files to frame the name of next new files.