Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Load file names from a directory to put in a DOS window


  • Please log in to reply
17 replies to this topic
Sam.
  • Members
  • 107 posts
  • Last active: Jul 15 2017 04:06 PM
  • Joined: 14 Nov 2008
Hello again,

I am trying to make a GUI for a DOS program which combines two video files together. I have made the basic layout of the GUI which (among other things) allows the user to load all of the files to be combined into a particular folder. What is the best way to determine and then store the names of all .MVE video files in that directory to a variable (or variables?) that can then send the names to command prompt: 2 the first time and then only 1 each additional time until all of the files have been combined?

Please keep in mind that while I am trying very hard to learn, I'm still relatively new to this sort of thing.

Thanks in advance,
Sam.

BoBo³
  • Guests
  • Last active:
  • Joined: --
Show your code.

Sam.
  • Members
  • 107 posts
  • Last active: Jul 15 2017 04:06 PM
  • Joined: 14 Nov 2008
;

; AutoHotkey Version: 1.x

; Language:       English

; Platform:       Win9x/NT

; Author:         A.N.Other <[email protected]>

;

; Script Function:

;	Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)

;



#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.

SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.











;FileAppend, MVE~AVI gui launched...`n, %A_ScriptDir%\MVE~AVI gui log.txt

Gui, Font, S12 CDefault Bold, Verdana

Gui, Font, S8 CDefault Bold, Verdana

Gui, Add, ListView, x406 y70 w180 h400, Name

Loop, %A_ScriptDir%\MVE~AVI gui (temp)\*.mve*

    LV_Add("", A_LoopFileName, A_LoopFileSizeKB)

LV_ModifyCol()  ; Auto-size each column to fit its contents.

Gui, Add, Text, x406 y50 w180 h20 +Center, Loaded MVE Chunks:

Gui, Font, S8 CDefault Bold, Verdana

FileRead, log, %A_ScriptDir%\MVE~AVI gui log.txt

Gui, Add, Edit, x16 y70 w350 h400 +ReadOnly, %log%

Gui, Add, Text, x16 y50 w350 h20 +Center, Event Log:

Gui, Add, Picture, x476 y520 w50 h50 , E:\AutoHotkey scripts\Images\PSicon48x48.ico

Gui, Add, Button, x486 y10 w100 h30 , About

Gui, Add, Button, x16 y10 w130 h30 , Load MVE Chunks

Gui, Add, Button, x256 y10 w100 h30 , Help

Gui, Add, Button, x216 y530 w170 h30 , Combine Loaded Chunks

Gui, Add, Button, x406 y480 w180 h30 , Delete Loaded Chunks

Gui, Add, Button, x16 y480 w350 h30 , Clear Event Log

Gui, Show, x131 y91 h582 w609, MVE~AVI gui

Return











GuiClose:

;FileAppend, MVE~AVI gui closed...`n, %A_ScriptDir%\MVE~AVI gui log.txt

ExitApp



GUIRestart:

RUN, %A_ScriptDir%\MVE~AVI gui.ahk

Goto, GuiClose











ButtonLoadMVEChunks:

     {



; Multi-Select Example:

FileSelectFile, MVE_files, M3, %A_ScriptDir%, Select an Interplay video (.MVE) file:, Interplay video file (*.mve)   ; M3 = Multiselect existing files.

if MVE_files =

{

    return

}

Loop, parse, MVE_files, `n

{

    if a_index = 1

    {

        ;MsgBox, The selected files are all contained in %A_LoopField%.

	MsgBox, 0, , This may take a few minutes.  Please wait.

    }

    else

    {

        FileCopy, %A_LoopField%, %A_ScriptDir%\MVE~AVI gui (temp)\  ; Make a copy but keep the orig. file name.

	FileAppend, %A_LoopField% loaded...`n, %A_ScriptDir%\MVE~AVI gui log.txt

    }





}

Goto, GUIRestart

return

     }











ButtonClearEventLog:

	{

	FileDelete, %A_ScriptDir%\MVE~AVI gui log.txt

	FileRead, log, %A_ScriptDir%\MVE~AVI gui log.txt

	FileAppend, Log was reset...`n, %A_ScriptDir%\MVE~AVI gui log.txt

	Goto, GUIRestart

	return

	}











ButtonDeleteLoadedChunks:

	{

	FileDelete, %A_ScriptDir%\MVE~AVI gui (temp)\*.MVE

	FileAppend, Temporary files purged...`n, %A_ScriptDir%\MVE~AVI gui log.txt

	Goto, GUIRestart

	return

	}











;ButtonCombineLoadedChunks:

;	{

;	BlockInput, on

;	ControlSend, , , cmd.exe



svi
  • Members
  • 237 posts
  • Last active: Mar 09 2015 06:34 PM
  • Joined: 09 Oct 2006
Is there a specific reason why you copy the video files to a temporary folder ("MVE~AVI gui (temp)")?
That's slow, and if you press "Delete Loaded Chunks", they're maybe not deleted before the script gets rerun, so in "Loaded MVE Chunks" there might be filenames whose targets have been deleted.
My "old" computer is too slow to delete 3 files (invalid, size 0), but too quick to rerun the script, so in my two tests one filename was left to the list.
Pekka Vartto

Sam.
  • Members
  • 107 posts
  • Last active: Jul 15 2017 04:06 PM
  • Joined: 14 Nov 2008

Is there a specific reason why you copy the video files to a temporary folder ("MVE~AVI gui (temp)")?
That's slow, and if you press "Delete Loaded Chunks", they're maybe not deleted before the script gets rerun, so in "Loaded MVE Chunks" there might be filenames whose targets have been deleted.
My "old" computer is too slow to delete 3 files (invalid, size 0), but too quick to rerun the script, so in my two tests one filename was left to the list.

Well, the MVE_Joiner (which can be found here) is a DOS program that only combines 2 MVE chunks at a time, so in the DOS window you have to have <mve_join.exe> <name of the first chunk> <name of the second chunk> <output file name>. To add another chunk, you would have to then send <mve_join.exe> <the first output file name> <name of the third chunk> <the second output file name> and so on for each additional chunk.

If the files to be joined come from different directories, then you have to detect and then input the full file's path instead of just the file name which I thought would be a bit harder that just getting the file names (and not the full path) from one folder. Additionally, each of the progressive output files would have to have a different file name to avoid the user being prompted to overwrite the first file (which I want to avoid in part because I suspect I will have to block user input or hide the DOS window in order to get the DOS window to work right.) Once all of the loaded chunks have been combined, the intermediate output ones should be deleted automatically but leave the originals in tact.

If you know of a better way to get the same overall result, I am very open to your suggestions.

My "old" computer is too slow to delete 3 files (invalid, size 0), but too quick to rerun the script, so in my two tests one filename was left to the list.

How would I wait until all of the files are deleted before restarting?

Thanks for the interest in helping so far! I really appreciate it!

svi
  • Members
  • 237 posts
  • Last active: Mar 09 2015 06:34 PM
  • Joined: 09 Oct 2006
I guess that those video files are relative small, so copying them to a temp folder could be acceptable, but because copied or deleted files are not immediately updated in the folder (at least on slower computers), I prefer making only a variable containing paths and filenames.

A temporary folder is needed for combination output, but if you'd copy also input files, you would have to check if there are same names (from other folders).

Have you thought about files' combining sequence?
If it matters, then you'd have to have some "promote/denote" control, which AHK doesn't support, as far as I know.
Pekka Vartto

Sam.
  • Members
  • 107 posts
  • Last active: Jul 15 2017 04:06 PM
  • Joined: 14 Nov 2008

Have you thought about files' combining sequence?
If it matters, then you'd have to have some "promote/denote" control, which AHK doesn't support, as far as I know.

Well, when I had to use the DOS program by itself, I was combining several chunks of the same original file, so they were named in the order that they would need to be combined, like: Credits1, Credits2,... Credits17 so parsing the contents of the folder and storing them to a variable would have put them in the proper order, but I suppose mine was an optimal situation and most wouldn't be that nice....

I guess that those video files are relative small, so copying them to a temp folder could be acceptable, but because copied or deleted files are not immediately updated in the folder (at least on slower computers), I prefer making only a variable containing paths and filenames.

A temporary folder is needed for combination output, but if you'd copy also input files, you would have to check if there are same names (from other folders).

Well, it wouldn't be very pretty but when the files are opened, could the file names and paths be stored each to a separate line in a text file (or would a variable work better) that would then be loaded into an "Edit" box in the GUI that the user could cut/paste into the desired order? Then after the information is submitted, it would be read and sent to the DOS window in the desired order and without having to deal with copying/deleting/renaming the actual files.

svi
  • Members
  • 237 posts
  • Last active: Mar 09 2015 06:34 PM
  • Joined: 09 Oct 2006
I think I found a smart way to select files' combination sequence from explorer with a mouse.
If you're interested, I'll try to make the selection script "ready" tomorrow.
Pekka Vartto

Sam.
  • Members
  • 107 posts
  • Last active: Jul 15 2017 04:06 PM
  • Joined: 14 Nov 2008

I think I found a smart way to select files' combination sequence from explorer with a mouse.
If you're interested, I'll try to make the selection script "ready" tomorrow.

Awesome, thanks so much ! ! !

svi
  • Members
  • 237 posts
  • Last active: Mar 09 2015 06:34 PM
  • Joined: 09 Oct 2006
Ok, here's the script (this one's been tested few times):

GroupAdd explorer, ahk_class ExploreWClass
GroupAdd explorer, ahk_class CabinetWClass

+Esc:: ; Shift + Esc to exit
ExitApp

#IfWinActive ahk_group explorer

+Enter::
+NumpadEnter::
MsgBox %filelist%
Return

Enter::
NumpadEnter::
Clipboard =
Send ^c
ControlGet sel, List, Selected Col1, SysListView321, A
If sel =
	Return ; click occured outside item(s), no items were selected
ClipWait 0.2
If Clipboard =
	ControlGet sel, List, Selected Col1, SysListView321, A
	If sel =
		Return ; rapid cancel of selection occured!?
filelist .= Clipboard . "`n"
MsgBox Items were added to filelist
Return

~*LButton::
Clipboard =
Send ^c
ControlGet sel, List, Selected Col1, SysListView321, A
If sel =
	Return ; click occured outside item(s)
ClipWait 0.2
If Clipboard =
	ControlGet sel, List, Selected Col1, SysListView321, A
	If sel =
		Return ; rapid cancel of selection occured!?
StringSplit line, Clipboard, `n, `n `r
Loop %line0%
{
	a := A_Index
	If InStr(filelist, line%A_Index%)
		Continue
	filelist .= line%A_Index% . "`n"
}
ToolTip Items were added to filelist
SetTimer ttOff, -3000
Return

ttOff:
ToolTip
Return
When you select files with a mouse click, additional items are added in the order of clicking.
No deselection is available, so the state of Control key doesn't matter (but for clarity it's better to use Control key when adding items).
Items, which are in desired, alphabetic order in the current folder, may be selected with keyboard (ctrl + a, shift + arrows, ctrl + arrows + space), then pressing Enter.
You can collect items from several folders.

Press Shift + Enter, when the list is complete.

You can't select multiple items with mouse ("click and drag"?). To enable this would make the script more complicated (would have to detect the "left" button release, which would probably require a loop instead of a hotkey).
Pekka Vartto

Sam.
  • Members
  • 107 posts
  • Last active: Jul 15 2017 04:06 PM
  • Joined: 14 Nov 2008
It seems to be working great. Thanks svi! If you don't mind, I've got one more question, though. How should I send the lines to the command prompt at the appropriate time (send the next set after the previous ones have been processed and then end when all of the files that the user selected have been combined)?

Thank you so very, very much for all your help!!

svi
  • Members
  • 237 posts
  • Last active: Mar 09 2015 06:34 PM
  • Joined: 09 Oct 2006
You need to get the return value, so use eg. CMDRet.
I haven't tested it so far.

Simplier method would be to use FileMove to rename the output file. The errorlevel indicates the number of files that couln't be renamed/moved.
Use a loop to test when it becomes zero, ie. the file is complete (this method doesn't recognize errors).
Pekka Vartto

svi
  • Members
  • 237 posts
  • Last active: Mar 09 2015 06:34 PM
  • Joined: 09 Oct 2006
You could redirect errors to a file: Redirecting Error Messages from Command Prompt
Pekka Vartto

Sam.
  • Members
  • 107 posts
  • Last active: Jul 15 2017 04:06 PM
  • Joined: 14 Nov 2008
I've tried, and tried, and tried, but I'm just not knowledgeable and experienced enough to even be able to properly implement the scripts that you have shown me. I feel like I've learned a fair bit since starting this project, but I've been reminded again and again just how far I still have to go even to be decently good at this. It truly pains me to keep having to ask for help, but what I desperately want to accomplish is still just too far over my head to do without a considerable amount of help. If you can help me get this first portion of the program working, I'll be able to do the other 3 parts by myself. Thanks for the patience and help you have given me so far, svi.

I'm afraid this is as far as I have been able to muddle through so far:
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <[email protected]>
;
; Script Function:
;	Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Create the sub-menus for the menu bar:
Menu, FileMenu, Add, &Exit, FileExit
Menu, ViewMenu, Add, &Log, ViewLog
Menu, HelpMenu, Add, &HelpFile, HelpFile
Menu, HelpMenu, Add, &License, HelpLicense
Menu, HelpMenu, Add, &Credits, HelpCredits
Menu, HelpMenu, Add, &About, HelpAbout


; Create the menu bar by attaching the sub-menus to it:
Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &View, :ViewMenu
Menu, MyMenuBar, Add, &Help, :HelpMenu
;Gui, 1:Show, x131 y91 h480 w640, MVE~AVI gui
Gui, 1:Menu, MyMenuBar
Gui, 1:Add, Tab2, x6 y20 w620 h420 , MVE Joiner|MVE 2 EXE|MVE 2 AVI|AVI 2 MVE
Gui, 1:Tab, MVE Joiner
;Gui, 1:Add, Text, x246 y213 w140 h20 , Where "MVE Joiner" will go!
Gui, 1:Font, S8 CDefault Bold, Verdana
Gui, 1:Add, Button, x251 y50 w130 h30 , Load MVE Chunks
Gui, 1:Add, Button, x231 y400 w170 h30 , Combine Loaded Chunks
Gui, 1:Add, Edit, x10 y100 w610 h280 +ReadOnly, If I understand correctly, the information that CMDRet outputs as well as any error messages could be displayed here?
Gui, 1:Add, Text, x10 y80 w170 h20 , Conversion Progress:



Gui, 1:Tab, MVE 2 EXE
Gui, 1:Add, Text, x246 y213 w180 h20 , Where "MVE 2 EXE" will go!
Gui, 1:Tab, MVE 2 AVI
Gui, 1:Add, Text, x246 y213 w180 h20 , Where "MVE 2 AVI" will go!
Gui, 1:Tab, AVI 2 MVE
Gui, 1:Add, Text, x246 y213 w180 h20 , Where "AVI 2 MVE" will go!
; Generated using SmartGUI Creator 4.0
;Gui, 1:Show, x131 y91 h450 w636, New GUI Window
Menu, MyMenuBar, Color, F5F5F5 
Gui, 1:Show, h450 w636, New GUI Window
Return



;Return



FileExit:     ; User chose "Exit" from the File menu.
GuiClose:  ; User closed the window.
ExitApp
return

ViewLog:
IfExist, %A_ScriptDir%\MVE~AVI gui log.txt
    {
    Run, %A_ScriptDir%\MVE~AVI gui log.txt
    }
    else {
    MsgBox, , , The log does not exist.
    }
return

HelpFile:
IfExist, %A_ScriptDir%\MVE~AVI gui Help File.html
    {
    Run, %A_ScriptDir%\MVE~AVI gui Help File.html
    }
else {
    MsgBox, , , The Help File does not exist.
    }
return

HelpLicense:
IfExist, %A_ScriptDir%\MVE~AVI gui License.html
    {
    Run, %A_ScriptDir%\MVE~AVI gui License.html
    }
else {
    MsgBox, , , The License does not exist.
    }
return

HelpCredits:
IfExist, %A_ScriptDir%\MVE~AVI gui Credits.html
    {
    Run, %A_ScriptDir%\MVE~AVI gui Credits.html
    }
else {
    MsgBox, , , The Credits File does not exist.
    }
return

HelpAbout:
MsgBox, , , File is under construction!`nBasically created by svi at the begging of Sam.
return



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ButtonLoadMVEChunks:
     {
	GroupAdd explorer, ahk_class ExploreWClass
GroupAdd explorer, ahk_class CabinetWClass
	Run, %A_ScriptDir%
	Sleep, 1000
	MsgBox, , , When you select files with a mouse click, additional items are added in the order of clicking.`nNo deselection is available, so the state of Control key doesn't matter (but for clarity it's better to use Control key when adding items).`nItems, which are in desired, alphabetic order in the current folder, may be selected with keyboard (ctrl + a, shift + arrows, ctrl + arrows + space), then pressing Enter.`nYou can collect items from several folders.`n`nPress Shift + Enter, when the list is complete.`nPress Shift + Escape to exit file loading mode.`nYou can't select multiple items with mouse ("click and drag"?).

+Esc:: ; Shift + Esc to exit
WinMinimizeAll
WinActivate, New GUI Window
MsgBox, , , Test was completed successfully.
Return


#IfWinActive ahk_group explorer

+Enter::
+NumpadEnter::
MsgBox %filelist%
Return

Enter::
NumpadEnter::
Clipboard =
Send ^c
ControlGet sel, List, Selected Col1, SysListView321, A
If sel =
   Return ; click occured outside item(s), no items were selected
ClipWait 0.2
If Clipboard =
   ControlGet sel, List, Selected Col1, SysListView321, A
   If sel =
      Return ; rapid cancel of selection occured!?
filelist .= Clipboard . "`n"
MsgBox Items were added to filelist
Return

~*LButton::
Clipboard =
Send ^c
ControlGet sel, List, Selected Col1, SysListView321, A
If sel =
   Return ; click occured outside item(s)
ClipWait 0.2
If Clipboard =
   ControlGet sel, List, Selected Col1, SysListView321, A
   If sel =
      Return ; rapid cancel of selection occured!?
StringSplit line, Clipboard, `n, `n `r
Loop %line0%
{
   a := A_Index
   If InStr(filelist, line%A_Index%)
      Continue
   filelist .= line%A_Index% . "`n"
}
ToolTip Items were added to filelist
SetTimer ttOff, -3000
Return

ttOff:
ToolTip
Return

	MsgBox, , , Test was completed successfully.
	return
     }
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;




ButtonCombineLoadedChunks:
	{


return
	}


garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005
hello Sam.
didn't checked script , but editfield should have a variable to control later

Gui, 1:Add, Edit, x10 y100 w610 h280 +ReadOnly vOutput1,
--
--
GuiControl,1:Text,output1,%cmdretoutput%


here an example with listbox
mycmd     =netstat -e -s
srch      =send                ;this search for the word "send"

F3        =test53.txt      ;only searched string
F4        =test54.txt      ;the DOS command output
Gui,1:Font,,FixedSys
Gui,1:Add,Listbox, x10  y5    h190  w680 vLB1,
Gui,1:Add,button,  x20  y200  h20   w100 gSTART,START
Gui,1:Show, x0 y0 h225 w700 , Searched string=  %srch%   for=  %mycmd%
return
;-------------------------------------------------------

START:
Gui,1:submit,nohide
GuiControl,1:,LB1,|                       ;clear listbox

runwait,%comspec% /c %mycmd% |find /I "%srch%" >%F3%,,hide     ;shows only   found string
runwait,%comspec% /c %mycmd% |find /V "XXXBBB" >%F4%,,hide     ;shows always all

Loop,read,%F3%
   GuiControl,1:,LB1,%A_LoopReadLine%     ;listbox shows only lines with found words
run,%F4%                                  ;this file shows all
return
;--------------------------------------------------------

Guiclose:
exitapp

other examples
;-------------- SENDTODOS------------------------------------------------
;example1
run,%comspec% /K
sleep,500
SendMode, Input
#IfWinActive ahk_class ConsoleWindowClass
;SendRaw, %ClipBoard%
Sendraw,dir
send,{enter}
#IfWinActive
return
;------------------------------


;----------------------------------- DOS COMMAND SHOW --------------------
;example2:
mycmd      =vol
srch       =volume
F3         =test55.txt
Gui,1:Font,,FixedSys
Gui,1:Add,Edit,cRed x10 y0   h25  w480 vOUTPUT2,
Gui,1:Show,         x0  y0   h30  w500 ,DOS-command=%mycmd% > search for the text "%srch%"
runwait,%comspec% /c %mycmd% |find /I "%srch%" >%F3%,,hide
       FileReadLine,VAR1,%F3%,1
       stringmid,S1,VAR1,1,200
       S1=%S1%
       GuiControl,1:,OUTPUT2,%S1%
       msgbox,DOS-command=%mycmd%`n%S1%
return

Guiclose:
exitapp