vb.net Exclude extension from "GetFiles" - vb.net

I'm currently adding all found documents in a directory and sub-directory into a listbox.
This works perfectly, for my need, but i'm getting too much unwanted files.
The code for adding the files into my listbox:
ES_MAIN_SPECIFICATIONS_LIST.Items.AddRange(IO.Directory.GetFiles(oFolder, "*", IO.SearchOption.AllDirectories))
The * makes that all files are included but how can I exclude a certain extention?

You will need to then loop through again, removing those with the extensions you don't want. You can also use LINQ (.Where(...)) to do the same thing inline:
ES_MAIN_SPECIFICATIONS_LIST.Items.AddRange(IO.Directory.GetFiles(oFolder, "*", IO.SearchOption.AllDirectories).Where(Function(p) Not IO.Path.GetExtension(p).Equals("excludeMe"))

Related

How to copy and rename multiple files in CMake with wildcards?

I have a CMake project and I need to copy files from one folder to another and do some additional renaming with the following pattern:
"xy-1" will be "abcd1",
"xy-2" will be "abcd2",
...,
"xy-123" will be "abcd123"
Currently I´m trying this with add_custom_command() and in general it works for a simpler pattern like
"xy-1" will be "abc1",
"xy-2" will be "abc2",
...,
"xy-123" will be "abc123",
I´m doing it with
COMMAND copy "${path_to_source_folder}xy-*.txt" "${path_to_destination_folder}abc*.txt"
In the working pattern the number of characters before the asterisk are the same for the source- and the destination-name.
But in the not working pattern, there are 3 characters in the source-name and four characters in the destination-name before the asterisk:
COMMAND copy "${path_to_source_folder}xy-*.txt" "${path_to_destination_folder}abcd*.txt"
This not working. There is no error coming from cmake, but it will not copy all files (only the first 99) and the names are not created properly.
A quick fix would be to list all (400+) files explicitly, but I´d like to avoid this ;-)
How to do this with add_custom_command() or if this is not possible, how to do it in another way?
Many thanks for your help!
Cheers Daniel
Upate:
Thanks for the hints in the comments! I´m running on Windows 10 and using powershell for running cmake.

VB.net rename each file in a directory

Id like to rename all my files in one specific directory. They shall all get the identical extension. I tried using a for loop:
For Each s As String In IO.Directory.GetFiles(Environ("PROGRAMFILES(x86)"), "*", IO.SearchOption.AllDirectories)
Try
My.Computer.FileSystem.RenameFile(s, s & ".new")
Catch ex As Exception
End Try
So that the name s (as string) becomes s & extension ".new"
However, that didnt work.
If you had read the documentation for the RenameFile method you are calling, as you should have to begin with but especially when it didn't work, then you would know that the first argument requires the full path of the file while the second argument requires just the new name of the file. That means that you need this:
My.Computer.FileSystem.RenameFile(s, My.Computer.FileSystem.GetName(s) & ".new")
The File.Move method requires full paths in both cases because it supports renaming within the same folder and moving to a different folder. You say that you want to use RenameFile but didn't bother to note how it is different, i.e. it only supports renaming within the same folder so specifying that path twice is pointless and allowing different paths to be specified would cause problems.

Labview : delete files having same extension

I've been trying to delete files having same extension by using labview.
I am using delete.vi to delete files like below.
But, I want to delete all files having same extension.
Imagine a folder like below.
Here, I would like to delete all files having '.MASTER, .jou, .IFPDAT, . f06, .f04, .DBALL' as extension.
I would like to make an automatic file delete function like below.
Would there be any good examples?
The best way is to use "List Folder" with wild-cards (using "pattern" input) to get an array of files. Then you have to delete files one by one.
You can use System Exec.vi.
Here's an example to delete all DXF files in a folder:
Drawback: portability

CLOC- count lines of code, exclude everything in a dir except for certain files

I am using cloc to count our code. We need to exclude everything in a directory, except for files with a specific form like *instru.c. Is it possible to use the exclude and include files to do this?

WinSCP Session::RemoveFiles - Delete specified files in sub directories

[Question] Does Session::RemoveFiles() remove files in sub directory of source directory? If not, how to implement this ability?
(Please do not ask me why I have the remote directory as /C/testTransfer/. The code just for testing purpose.)
I have a SFTP program using WinSCP .Net assembly. Program language is C++/CLI. It opens up a work file. The file contains many lines of FTP instructions.
One type of instruction I have to handle is to transfer *.txt from source directory. The source directory may contain sub directories which may contain .txt as well. Once transfer is successful, delete the source files.
I use Session::GetFiles() for the transfer. It correctly transfer all .txt files (/C/testTransfer/*.txt), even those in sub directories (/C/testTransfer/sub/*.txt), in the source to the destination.
transferOptions->FileMask = "*.txt";
session->GetFiles("/C/testTransfer", "C:\\temp\\win", false, transferOption);
Now to remove, I use session->RemoveFiles("/C/testTransfer/*.txt"). I only see *.txt in the source (/C/testTransfer/*.txt), but not in the sub directory (/C/testTransfer/sub/*.txt), are removed.
The Session::RemoveFiles can remove even files in subdirectories in general. But not this way with wildcard, because WinSCP will not descend to subdirectories that do not match the wildcard (*.txt). Also note that even if you do not need the wildcard, the Session::RemoveFiles would remove even the subdirectories themselves, what I'm not sure you want it to.
Though you have other (and better = more safe) options:
Use the remove parameter of the Session::GetFiles method to instruct it to remove source file after successful transfer.
If you need to delete source files transactionally (=only after download of all files succeed), iterate the TransferOperationResult::Transfers returned by Session::GetFiles and call the Session::RemoveFiles for each (unless the TransferEventArgs::Error is not null).
Use the TransferEventArgs::FileName to get a file path to pass to the Session::RemoveFiles. Use the RemotePath::EscapeFileMask to escape the file name before passing it to the Session::RemoveFiles.
There's a similar full example available for Moving local files to different location after successful upload.
To recursively delete files matching a wildcard in a standalone operation (not after downloading the same files), use the Session::EnumerateRemoteFiles. Pass your wildcard to its mask argument. Use the EnumerationOptions.AllDirectories option for recursion.
Call the Session::RemoveFiles for each returned file. Use the RemotePath::EscapeFileMask to escape the file name before passing it to the Session::RemoveFiles.