Jump to content

FileListToArray recursive with max depth


phonk
 Share

Recommended Posts

Hi M23,

Can use show me example code using this UDF? I would like to search folder ABC from $source_folder. If found then copy entire folder to $dest_folder. If not found that find any files which name contain string ABC in it and copy to $dest_folder

Thanks for your help and your time :)

Answering my own question: searching through this forum I found a example code for _RecFileListToArray. Let me try to code it first because asking more questions :)

Link to comment
Share on other sites

  • Moderators

michaelslamet,

Delighted you want to try and code something yourself - I will be here if you run into difficulties. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

michaelslamet,

Delighted you want to try and code something yourself - I will be here if you run into difficulties. ;)

M23

Thanks M23 :)

And this is my first difficulties :P

using _RecFileListToArray I found a folder that match my criteria:

$search_result = _RecFileListToArray(GUICtrlRead($location), "*" & $find_criteria & "*", 2, 1, 0, 2)

I try to copy the result to $dest_folder:

DirCopy($search_result[$counter], @Desktopdir & "\", 1)

The problem is DirCopy only copy the content of folder $search_result to $dest_folder, not the folder itself.

example:

search result: folder ABC, which is contain 1.txt and 2.txt

Dircopy will copy the 1.txt and 2.txt to $dest_folder so $dest_folder will content 1.txt and 2.txt

I want $dest_folder contain folder ABC and inside folder ABC there is 1.txt and 2.txt

This is not a _RecFileListToArray problem :D

And I hope you can understand what i'm trying to say :)

:)

Link to comment
Share on other sites

  • Moderators

michaelslamet,

You just need to correctly specify the destination path that you want. :P

I assume that $search_result[$counter] looks like this - Path\path\path\ABC. You need to get the ABC part of the total path and then do this:

DirCopy($search_result[$counter], @Desktopdir & "\ABC", 1)

Now the command will create the ABC folder on the desktop and copy over the files within as you wish. :)

You might find this useful to get the folder name from the path: :D

$sPath = "Path\path\path\ABC"

$sFolder = StringRegExpReplace($sPath, "^.*\\(.*)", "\1")

ConsoleWrite($sFolder & @CRLF)

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

michaelslamet,

You just need to correctly specify the destination path that you want. ;)

I assume that $search_result[$counter] looks like this - Path\path\path\ABC. You need to get the ABC part of the total path and then do this:

DirCopy($search_result[$counter], @Desktopdir & "\ABC", 1)

Now the command will create the ABC folder on the desktop and copy over the files within as you wish. :)

You might find this useful to get the folder name from the path: :)

$sPath = "Path\path\path\ABC"

$sFolder = StringRegExpReplace($sPath, "^.*\\(.*)", "\1")

ConsoleWrite($sFolder & @CRLF)

All clear? :P

M23

haha, thanks a lot M23 :)

Works great now :D this is the modified code, your StringRegExp to get the folder name is so great!

$search_result = _RecFileListToArray(GUICtrlRead($location), "*" & $find_criteria & "*", 2, 1, 0, 2)
For $counter = 1 to $search_result[0]
  $folder_name_only = StringRegExpReplace($search_result[$counter], "^.*\\(.*)", "\1") 
  DirCopy($search_result[$counter], @Desktopdir & "\" & @desktopdir & "\" & $folder_name_only, 1)
Next
Link to comment
Share on other sites

michaelslamet,

You just need to correctly specify the destination path that you want. :D

I assume that $search_result[$counter] looks like this - Path\path\path\ABC. You need to get the ABC part of the total path and then do this:

DirCopy($search_result[$counter], @Desktopdir & "\ABC", 1)

Now the command will create the ABC folder on the desktop and copy over the files within as you wish. :)

You might find this useful to get the folder name from the path: ;)

$sPath = "Path\path\path\ABC"

$sFolder = StringRegExpReplace($sPath, "^.*\\(.*)", "\1")

ConsoleWrite($sFolder & @CRLF)

All clear? :P

M23

Hi M23, question again :)

The search result, can we know which one is file and which one is folder, if we choose to get both files and folder?

Link to comment
Share on other sites

  • Moderators

michaelslamet,

Read the function header: :)

$sPath - Initial path used to generate filelist. If path ends in \ then folders will be returned with an ending \

Then a simple StringRight($var, 1) will let you know. :)

M23

P.S. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :P

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

michaelslamet,

Delighted I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...