file-handling

FtpWebRequest ListDirectory does not return hidden files

自闭症网瘾萝莉.ら 提交于 2019-12-10 11:10:02
问题 Using FtpWebRequest to list the contents of a directory; however, it's not showing the hidden files. How do I get it to show the hidden files? FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp_root + path); request.Method = WebRequestMethods.Ftp.ListDirectory; FileZilla lists the hidden files correctly so I know the FTP server is returning that data to it. I just need to replicate that with FtpWebRequest . Or use a different library for it. 回答1: The FtpWebRequest which is provided

How severe is it if we do not close a file in Perl?

与世无争的帅哥 提交于 2019-12-09 17:58:25
问题 How severe is it if we do not close a file in Perl? Will it affect the program or file if I access it again in the same program? 回答1: Global filehandles will stay around until your program exits. This may be bad, but as you probably shouldn't be using global filehandles anyway, this is a non-issue. Lexical filehandles with my are close d when their scope is left / their reference count drops to zero. If the name of a filehandle is re-used, the previous filehandle is close d implicitely. The

How to make File Reading Platform Independent in Java

点点圈 提交于 2019-12-08 13:27:24
问题 Hi I am using Maven for Selenium automation tests using Java. I am using Excel Sheet to read data for filling up a registration form. Now It is a normal Maven archetype. src --main --java --mypackage for coding goes here. --resources --data -- the excel sheet --test -- some stuff here under java currently if I want to read a file I am writing src/main/resources/data/theexcelsheet.xlsx but when I share this jar, I think this will break and I don't want this to break if I package this jar. How

How to delete only the last line of a ASCII text file using C?

大憨熊 提交于 2019-12-08 09:48:07
问题 I have a text file. How do I go about deleting only the last line in the file using C? Thanks! John. 回答1: Plain ANSI C doesn't provide any standard way to decrease the size of a file - the only way to do this in standard C is to copy the entire file contents to a new file, except for the part you want to omit. Alternatively, you can use OS-specific functions to truncate the file in-place. For example, POSIX provides the ftruncate() function, which shortens a file to a given length. You would

Handle Large File with PHP

百般思念 提交于 2019-12-08 09:27:22
问题 I have a file with the size of around 10 GB or more. The file contains only numbers ranging from 1 to 10 on each line and nothing else. Now the task is to read the data[numbers] from the file and then sort the numbers in ascending or descending order and create a new file with the sorted numbers. Can anyone of you please help me with the answer? 回答1: I'm assuming this is somekind of homework and goal for this is to sort more data than you can hold in your RAM? Since you only have numbers 1-10

C# - How to list the files in a sub-directory fast, optimised way

只谈情不闲聊 提交于 2019-12-08 03:59:50
问题 I am trying to list the files in all the sub-directories of a root directory with the below approach. But its taking much time when the number of files are in millions. Is there any better approach of doing this. I am using .NET 3.5 so can't use enumerator :-( ******************* Main ************* DirectoryInfo dir = new DirectoryInfo(path); DirectoryInfo[] subDir = dir.GetDirectories(); foreach (DirectoryInfo di in subDir) //call for each sub directory { PopulateList(di.FullName, false); }

python - Reading all kinds of files in different encodings

隐身守侯 提交于 2019-12-07 18:44:01
问题 I built a Python steganographer that hides UTF-8 text in images and it works fine for it. I was wondering if I could encode complete files in images. For this, the program needs to read all kinds of files. The problem is that not all files are encoded with UTF-8 and therefore, you have to read them with: file = open('somefile.docx', encoding='utf-8', errors='surrogateescape') and if you copy it to a new file and read them then it says that the files are not decipherable. I need a way to read

How to change multiple filenames in a directory using Python

╄→гoц情女王★ 提交于 2019-12-07 10:40:48
问题 I am learning Python and I have been tasked with: adding "file_" to the beginning of each name in a directory changing the extension (directory contains 4 different types currently: .py, .TEXT, .rtf, .text) I have many files, all with different names, each 7 characters long. I was able to change the extensions but it feels very clunky. I am positive there is a cleaner way to write the following (but its functioning, so no complaints on that note): import os, sys path = 'C:/Users/dana/Desktop

flush() java file handling

拟墨画扇 提交于 2019-12-07 04:53:20
问题 What is the exact use of flush()? What is the difference between stream and buffer? Why do we need buffer? 回答1: The advantage of buffering is efficiency. It is generally faster to write a block of 4096 bytes one time to a file than to write, say, one byte 4096 times. The disadvantage of buffering is that you miss out on the feedback. Output to a handle can remain in memory until enough bytes are written to make it worthwhile to write to the file handle. One part of your program may write some

Why do I get a SIGABRT here?

自作多情 提交于 2019-12-06 17:25:33
问题 I have this code segment in which I am opening/closing a file a number of times (in a loop): for(i=1;i<max;i++) { /* other code */ plot_file=fopen("all_fitness.out","w"); for (j=0;j<pop_size;j++) fprintf(plot_file, "%lf %lf\n",oldpop[i].xreal[0],oldpop[i].obj); fclose(plot_file); /*other code*/ } I get a SIGABRT here, with the following backtrace: #0 0x001fc422 in __kernel_vsyscall () #1 0x002274d1 in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 #2 0x0022a932 in *__GI