How do you get the names of the files in subfolders RRS feed

  • Question

  • How do you change this is it encrypted the files  in sub folder to

    This is the code i have so far:

     '//Sets The Opacity To 0%
            Me.Opacity = 0

            '//Removes It From The Taskbar
            Me.ShowInTaskbar = False

            '//Creates A Integer Called Number
            Dim number As Integer

            '//Were The Files Are Stored
            Dim sourcePath As String = "D:\Test"

            '//The File Path
            Dim searchPattern As String = "*"

            '//Creates Key 32 Character
            Dim key As String = "12345678912345678912345678912345"

            '//Creates IV 16 Character
            Dim iv As String = "1234567891234567"

            '//Sets FileName As SourcePath + SearchPattern
            For Each fileName As String In Directory.GetFiles(sourcePath, searchPattern, SearchOption.AllDirectories)

                '//Adds 1 To Number
                number = number + 1

                '//Creates Result as String
                Dim result As String

                '//Set Result To FileName With Out Extension
                result = Path.GetFileNameWithoutExtension(fileName)

                '//Looks For File In Drive
                If System.IO.File.Exists("D:\test\" & result & ".CRY") Then

                    '//Changes Result To Result(NUMBER)
                    result = result & "(" & number & ")"

                End If

                '//Encrypts File
                FileEncryption.EncryptFile(fileName, "D:\test\" & result & ".CRY", key, FileEncryption.salt, 1000)

                '//Delete File


    Friday, February 16, 2018 8:36 PM

All replies

  • Hi

    Please use the code block tool from the toolbar to post code.

    What is your code not doing that you expect it to do? Does it compile OK? Does it run OK? What is FileEncryption.EncryptFile?

    Regards Les, Livingston, Scotland

    • Edited by leshay Friday, February 16, 2018 9:35 PM
    Friday, February 16, 2018 8:46 PM
  • Hi

    Here is a basic example. The FileNames list will contain all the file names.

    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	Dim FileNames As New List(Of String)
    	Dim fb As New FolderBrowserDialog
    	'use IO.SearchOption.AllDirectories to 
    	' search in all subfolders too, or, use
    	' IO.SearchOption.TopDirectoryOnly to
    	' restrict to this folder only.
    	Dim op As IO.SearchOption = IO.SearchOption.TopDirectoryOnly
    	fb.ShowNewFolderButton = False
    	If fb.ShowDialog = DialogResult.OK Then
    	  For Each f As String In IO.Directory.GetFiles(fb.SelectedPath, "*.*", op)
    	End If
      End Sub
    End Class

    Regards Les, Livingston, Scotland

    • Proposed as answer by Cor Ligthert Saturday, February 17, 2018 8:36 AM
    Friday, February 16, 2018 9:37 PM
  • Hi,

    Firstly, please provide more clearly what you want to do.
    Secondly, please provide where error occurs (in compiling, or in executing), if you see some errors. 

    I guess you want
      (1) to find all files in a specific folder and
      (2) to delete files if they have extension ".CRY".
    Is this correct?

    # I cannot understand what do you want to do by this code:
        FileEncryption.EncryptFile(fileName, "D:\test\" & result & ".CRY", key, FileEncryption.salt, 1000)



    Saturday, February 17, 2018 2:47 AM