Trying to set up a script to go within a most recent subdirectory then within that latest directory, I would find multiple directories each containing a bunch of csv files that I ultimately want to copy over to 1 directory. Having trouble scripting the process of managing all these multiple subdirectories. I'm thinking I need to set up an array of subdirectories, choose one of interest. Go there and then get a new list of directories within that latest subdirectory. The look inside each of these directories and copy any csv files found there to one
centralized subdirectory. I have a network app that creates network data within monthly subdirectories based on the date. For example, I might see the following directories:
C:\reports\20180601 (for june as there is a 06 in directory name for 6th month)
C:\reports\20180701 (july)
C:\reports\20180801 (august)
so being that this is the month of august, I want a script to choose the latest "C:\reports\20180801" subdirectory and look inside it. Inside this directory should be about 40 to 80 subdirectories. The names of these directories are named from the network devices I have. Each of these directories might contain anywhere from 1 to 4 csv files. I want to get ALL csv files in all sub directories within C:\reports\20180801\<multiple subdirectories> to be copied to 1 centralized directory - maybe call it C:\myCSVfiles or something like that.
so I have:
C:\reports\20180801
|_ Network device 1
|_ Dev1report1.csv
|_ Dev1report2.csv
|_ Network device 2
|_ Dev2report1.csv
|_ Network device 3
|_ Dev3report1.csv
|_ Dev3report2.csv
|_ Dev3report3.csv
|_ Dev3report4.csv
in the above example, I would want all the csv files to get copied over to C:\myCSVfiles.. should see in that directory:
Dev1report1.csv
Dev1report2.csv
Dev2report1.csv
Dev3report1.csv
Dev3report2.csv
Dev3report3.csv
Dev3report4.csv
looking inside multiple subdirectories and copying files
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 2
- Joined: Wed Aug 08, 2018 9:57 am
Re: looking inside multiple subdirectories and copying files
Hello,
I've done this before. I mean managing folders in folders. What I did is get a list of folders each time you change into a folder. Then use the While command and loop through the list of folders.
I will write some code and post it for you. But for now maybe this gives you the idea.
I didn't read what you wrote thoroughly, I see you said the same thing. Well this is what I have written. It is a little rough, but it may be helpful.
I've done this before. I mean managing folders in folders. What I did is get a list of folders each time you change into a folder. Then use the While command and loop through the list of folders.
I will write some code and post it for you. But for now maybe this gives you the idea.
I didn't read what you wrote thoroughly, I see you said the same thing. Well this is what I have written. It is a little rough, but it may be helpful.
Code: Select all
OnEvent>Key_Down,VK113,0,DoExit
let>StartFolder=C:\Program Files (x86)
let>Ext=txt
// Get list of csv files.
//GetFileList>%StartFolder%\*.%Ext%,FL
Dialog>Dialog1
object Dialog1: TForm
Left = 587
Top = 237
Width = 492
Height = 746
HelpContext = 5000
AutoScroll = True
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object MSMemo1: tMSMemo
Left = 0
Top = 0
Width = 476
Height = 708
AutoSize = False
AlignBottom = True
ScrollBars = ssBoth
Align = alClient
TabOrder = 0
end
end
EndDialog>Dialog1
Show>Dialog1
// Get list of folders.
let>GFL_Type=1
GetFileList>%StartFolder%\*.*,FolderList
Separate>FolderList,;,Folder
StringReplace>FolderList,;,crlf,FLDisplay
SetDialogProperty>Dialog1,MSMemo1,Text,%FLDisplay%
let>asd=0
While>asd<%Folder_count%
let>asd=%asd%+1
let>Temp=Folder_%asd%
// Get list of all folders in current folder.
GetFileList>%Temp%\*.*,FL
// Add list of folders to FolderList.
if>FL>{""}
ConCat>FolderList,FL
ConCat>FolderList,{";"}
endif
// Get count of all folders.
Separate>FolderList,;,Folder
StringReplace>FolderList,;,crlf,FLDisplay
SetDialogProperty>Dialog1,MSMemo1,Text,%FLDisplay%
if>asd=10000
mdl>Ready.
wait>120
exit
endif
// Create the slightest hesitation
// so macro can be easily stopped.
wait>.00000000000000000000000000001
EndWhile
mdl>%FolderList%
exit
ConCat>FileList,FolderList
ConCat>FileList,{";"}
srt>DoExit
exit
END>DoExit
exit
Last edited by PepsiHog on Thu Aug 09, 2018 4:39 pm, edited 1 time in total.
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
-
- Newbie
- Posts: 2
- Joined: Wed Aug 08, 2018 9:57 am
Re: looking inside multiple subdirectories and copying files
Thanks Pepsihog,
I have pulled down some sample scripts that appear to come pretty close to what I need, but I was getting errors on just the samples with no editing what-so-ever..
I know a few programming languages too, in fact I have a liberty basic program (working) that does all the file management correctly. it works the latest files according to the present date. its perfect.. The only problem I have is liberty basic will no work on the servers because of the operating system used there.. I wrote everything on a win7 device, texted it, and tried to push it up to the servers.. The servers dont like me because of that.
I have pulled down some sample scripts that appear to come pretty close to what I need, but I was getting errors on just the samples with no editing what-so-ever..
I know a few programming languages too, in fact I have a liberty basic program (working) that does all the file management correctly. it works the latest files according to the present date. its perfect.. The only problem I have is liberty basic will no work on the servers because of the operating system used there.. I wrote everything on a win7 device, texted it, and tried to push it up to the servers.. The servers dont like me because of that.
Re: looking inside multiple subdirectories and copying files
Ok. Well I posted my code so far. It needs work. But it works well enough that you can see the idea. At the top of the script you set the folder location to start at, and the extension you are looking for.
I have to go do stuffs, but if you need any more help, let me know.
(If you tried pushing stuff up me, I wouldn't like you either!)
Good Luck.
I have to go do stuffs, but if you need any more help, let me know.
(If you tried pushing stuff up me, I wouldn't like you either!)

Good Luck.
Last edited by PepsiHog on Wed Jan 23, 2019 5:22 pm, edited 1 time in total.
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
Re: looking inside multiple subdirectories and copying files
Hi PepsiHog,
I come across your code and it is what I am looking for.
I edited the folder and the file extension as I want to look for but the scripts seem like run never end.
My problem is how to get the file in a folder within sub folders by input the file name only.
Thanks
I come across your code and it is what I am looking for.
I edited the folder and the file extension as I want to look for but the scripts seem like run never end.
My problem is how to get the file in a folder within sub folders by input the file name only.
Thanks
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: looking inside multiple subdirectories and copying files
Try debugging before running it by it self...
Re: looking inside multiple subdirectories and copying files
Hi,
You will need to add an if statement for what file you are looking for.
Insert this directly above ==> // Create the slightest hesitation
You need to replace "namelookingforhere" with the filename you are searching for.
There are users on this forum that will write a macro for you at a cost.
I do not mind helping, but you need to do some of the programming.
Good Luck,
PepsiHog
You will need to add an if statement for what file you are looking for.
Insert this directly above ==> // Create the slightest hesitation
Code: Select all
let>GFL_Type=0
GetFileList>%StartFolder%\*.*,FileList
position>namelookingforhere,FileList,1,res
if>res>0
// Create a subroutine with what to do when file is found.
gosub>DoExit
// GoSuB>whatyounamedyoursubroutine
endif
There are users on this forum that will write a macro for you at a cost.
I do not mind helping, but you need to do some of the programming.
Good Luck,
PepsiHog
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!