is there a global function in windows to lists the files in a dir? - windows

which function windows is calling to list the files in a directory ?
thanks

You can use this functions to do a directory listing with the WIN32 API.
FindFirstFile, FindNextFile and FindClose
A full example can be found here
Listing the Files in a Directory WIN32 API
For a portable approach check this post:
"Get list of files in a directory using c/c++"

Didn't exactly get your question but won't using "dir" as system command do the job?
Correct me if I am wrong, coz the question itself wasn't very clear to me.
Edit - Hi John, this is the source code for listing directories.
http://msdn.microsoft.com/en-us/library/aa365200(VS.85).aspx
Hope this helps.

Related

How to recursively change file permissions only in a ruby script

I have been using the function FileUtils.chmod_R to recursively change files and directories permissions under a given path but now want to change only the file permissions and leave the directories as they are. Looking at the man page for this function I can't see how to do this and I would prefer not to do this with a bash script. Please can someone tell me if this is possible with the FileUtils.chmod_R function or would I have to write additional code to iterate over every file that exist under a given path (recursive) and then FileUtils.chmod it to the desire permission? I am a ruby newbie so please point me someplace if I am asking anything obvious
You could do something like below - this will change permissions of the list of files matched by Dir.glob.
FileUtils.chmod 0400, Dir.glob('/path/to/dir/**/*')
As mentioned in this thread,
Dir.glob("**/*/") # will return list of all directories
Dir.glob("**/*") # will return list of all files

Ruby - Search and collect files in all directorys

I'm trying to search for a certain file type within all directories on my unix system using a ruby script. I understand the following code will search all files ending with .pdf within the current directory:
my_pdfs = Dir['*pdf']
As well as:
my_pdfs = Dir.glob('*.pdf').each do |f|
puts f
end
But how about searching all directories and sub-directories for files with the .pdf extension?
Check out the Find module:
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/find/rdoc/Find.html
Using Dir.glob is less than ideal since globbing doesn't handle recursion nearly as well as something like find.
Also if you're on a *nix box try using the find command. Its pretty amazingly useful for one liners.
Maybe something like:
pdfs=Dir['/**/*.pdf']
?
Not using Linux right now, so don't know if that will work. The ** syntax implies recursive listing.

How do I get the directory where the executable is located?

I got the filename like this:
_TCHAR filename[_MAX_PATH];
GetModuleFileName(NULL,filename,sizeof(filename));
How do I remove the filename from this full path? Should I use regex?
You can use the Windows shell API function PathRemoveFileSpec to do this. Example usage is listed on the linked page.
Since you use VS++, you can use:
_splitpath and _wsplitpath functions to break apart path

How to move a text file using Oracle

I have two questions.
(1) how to make move text file from folder:
C:\Data\inbox\test.txt
to target Folder?
C:\Data\outbox\test.txt
(2) how to make get list of directory files in Folder?
C:\Data\inbox\
Thank you...
Oracle provides a package of utilities for working with files, UTL_FILE. Since 9i this has included the FRENAME() procedure, which works like the unix mv command. We can use it to rename the file and/or its directory. Note that the Oracle os account must have read and write privileges on both directories. Also this procedure uses DIRECTORY objects, rather than explicit paths.
As for getting a list of files in a directory, there is no Oracle built-in. One solution is to use a Java Stored Procedure. Tom Kyte has an example of this. Find it here. There is another way of doing it since 11.1.0.7, which is to use an external table pre-processor file. Adrian Billington wrote a nice article on this. The executed file is platform dependent.
Have a look at UTL_FILE?
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm
Where you say:
2-) Question Two
Folder: C:\Data\inbox\
how to make get directory files list ?
Tom Kyte has a nice solution shown here
begin
UTL_FILE.FCOPY (
'EMPLOYEE' , -- THIS IS A ORACLE DIRECTORY
'EmpInfo.TXT' , --FILE NAME
'PROM_INCR' , -- THIS IS A ORACLE DIRECTORY
'EmpInfo.TXT' ); -- DESTINATION FILE
end;
try this

How to search for a .htaccess file with Windows?

I am dealing with a massive nest of files and need to find a .htaccess file that is redirecting a single page in my website. I know how ridiculous this sounds: why not just check the directories the page is located within? But the problem is slightly more complicated than that. All I need though, is to search for every .htaccess file under the web folder. Trying a normal search doesn't allow me to select that type of file to search for, and searching for hidden files has just been (who knows why) ignoring the .htaccess files anyway. I can't download any new software to do this for me. but - there must be a way! Even if I could somehow list every file within a directory (and its subdirs) and then organize by file type and scroll down?
I could search for any file with the word "RewriteEngine" , but there are so many files, this would take forever.
Any ideas?
Thanks!
=/ notepad++ is not installed, and I don't have auth to install anything
Use the commandline.
findstr /s RewriteEngine .htaccess
Searches the current directory and all sub directories for .htaccess files containing the string RewriteEngine.
Try searching for files of the form: *htaccess
(spelled precisely like that in the search field)
have you tried using Notepad++. It has a 'Find in files...' option that you could specify the page that it's trying to redirect to, and you could have it check only in *.htaccess files.
Just a thought
Search All files and folders, in All or part of the filename: put ".htaccess" including the quotes.
in the command prompt:
for hidden files: dir /s /b /a:sh *.htaccess>C:\results.txt
for non-hidden files: dir /s /b *.htaccess>C:\results.txt
to search for "RewriteEngine" type dir /s /b rewriteengine
both of these will output the search results to a text file called "results"

Resources