Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

AutoHotkey: Gui for files listing v2

Hello experts,

The following AutoHotkey script allows me to list files and folders based on folder reported.

;====================================
;Gui: list files and folders attributes
;====================================

^+f::
Gui,Add,Text,xm,Select folder for file listing:
Gui,Add,Edit,vFolderPath w400
Gui,Add,Text,,Select folders to process:
Gui,Add,Radio,Checked vRecurse,&Recurse
Gui,Add,Radio,x+10,&NoRecurse
Gui,Add,Text,xm,Select information to put in file listing:
Gui,Add,Radio,Checked vFileInfo,&Filename (without path)
Gui,Add,Radio,x+10,Filename with &Path
Gui,Add,Button,xm gButtonOKFilesFoldersListing Default,&OK
Gui,Add,Button,x+10 gButtonCancelFilesFoldersListing,&Cancel
Gui,Show,,File Listing
Return

ButtonOKFilesFoldersListing:
Gui,Submit
If (SubStr(FolderPath,0,1)!="\")
  FolderPath:=FolderPath . "\"
FormatTime,CurrentDateTimeFilesFolders,,yyyyMM
TempFile:=FolderPath . CurrentDateTimeFilesFolders . "_listing.txt"
FileList:=""
If (Recurse=1)
{
		LoopMode:="FDR"
}
Else
{
		LoopMode:="FD"
}
FileList:=""
Loop,Files,%FolderPath%*.*,%LoopMode%
{
  If (FileInfo=1)
		{
    FileList:=FileList . A_LoopFileName . "`n"
  }
		Else
		{
    FileList:=FileList . A_LoopFileFullPath . "`n"
		}
}
Msgbox,,,LoopMode:%LoopMode% `nFileInfo:%FileInfo%
Clipboard:=FileList
ClipWait,2 ; wait for information to appear on clipboard
If (ErrorLevel=1)
{
		MsgBox,4144,Error,No text appearing after 2 seconds
		Return
}
Sort,FileList
FileDelete,%TempFile%
FileAppend,%FileList%,%TempFile%
Run,%TempFile%
Gui,Destroy
Return

ButtonCancelFilesFoldersListing:
Gui,Destroy
Return

Open in new window


I need some help to cover the following requirements:
1.Entitle first line of the file based on the file info selector: file full path or file name. This will allows me to have a proper file listing.
2.Add a new file selector composed by: A_LoopFileTimeModified "`t" A_LoopFileName "`n" and therefore have 3 files info choices. This will allows me to work on excel if I want to sort file listing or do another operations related to the date of files and folders.

I will try to do my best on requirement 2 however I need some assistance on requirement 1. I am aware that I can retrieve lines based on A_Index however I don't know how to set up the full process.

Thank you in advance for your help.
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Hi Luis,

> Entitle first line of the file based on the file info selector: file full path or file name.

I'm unclear on what you mean by this. I think you're saying that you want the first line of the output file (TempFile) to show what the FileInfo is for this run, but I'm not sure. If that's what you want, add this after line 55:

If (FileInfo=1)
  FileList:="Filename without path`n" . FileList
Else
  FileList:="Filename full path`n" . FileList

Open in new window

If that's not what you want, please explain further.

> Add a new file selector composed by: A_LoopFileTimeModified "`t" A_LoopFileName "`n" and therefore have 3 files info choices.

Add this after line 13:

Gui,Add,Radio,x+10,Filename with &Date

Open in new window

And change lines 37-44 to this:

  Switch FileInfo
  {
    Case 1:
    FileList:=FileList . A_LoopFileName . "`n"

    Case 2:
    FileList:=FileList . A_LoopFileFullPath . "`n"

    Case 3:
    FileList:=FileList . A_LoopFileTimeModified . "`t" . A_LoopFileName . "`n"
  }

Open in new window

Of course, if you do that, then your first item (my comment above about what to add after line 55) needs to be changed to support the new FileInfo=3 value, something like this:

Switch FileInfo
{
  Case 1:
  FileList:="Filename without path`n" . FileList

  Case 2:
  FileList:="Filename full path`n" . FileList

  Case 3:
  FileList:="Filename with date`n" . FileList
}

Open in new window

Also, move the Sort,FileList (line 54) to before line 47. Regards, Joe
Avatar of Luis Diaz

ASKER

Hi Joe,

>I think you're saying that you want the first line of the output file (TempFile) to show what

Yes, first line of temp file should have a header, based on file info choice. In other words listing starts at line 2. Can I proceed as recommended in your previous comment?
> Can I proceed as recommended in your previous comment?

Yes, and the attached file does it. Tested here on W10, but not all six possibilities...you should do that and let me know if any combination of the options does not work. Regards, Joe
AppendListFilesV2.ahk
Hi Joe,

I started the testing phase and it works, thank you very much for this proposal!

However following the testing phase I realized that the best is to have a .csv file instead a txt file. Why? Because If I want to work with data I can do it directly in excel. Due to this I changed the separator of mode 3 with the following ";" (semicolon) to have date and file attributes information in two columns, I supposed that your separator will be "," (comma).

Based on my tests I noticed two thinks, I don't know if we can adapt them:
1.Global remarks for the following GUI that we have covered: When the GUI is already opened I relaunched it I have the following message: I think this is consistent and as a result normal because I cannot relaunch a GUI with the same variable. Do you see an alternative to avoid this?
User generated image2.For file info choice 3, I was wondering if we can have two headers:
Instead of having file name with date
User generated imageHave Date for column 1 file name or full path for column 2.

I attached AutoHotkey version which included the csv delimiter and the new extension of filelist.

Let me know what do you think.
AppendListFilesV2.ahk
Hi Luis,

> I started the testing phase and it works

Glad to hear it.

> If I want to work with data I can do it directly in excel.

No need for a CSV in this case due to the simplicity of the data. Excel handles a tab-separated TXT file nicely (see below).

> Do you see an alternative to avoid this?

There are numerous ways to handle this. The simplest is to destroy the GUI (Gui,Destroy) before relaunching it.

> Have Date for column 1 file name or full path for column 2.

Currently, when there is a Date in column 1, then column 2 can be file name only, not full path. If you want to be able to have full path, then you need a fourth FileInfo choice, such as:

1: without path without date
2: with path without date
3: without path with date
4: with path with date

> I attached AutoHotkey version which included the csv delimiter and the new extension of filelist.

I did not look at your version. Attached is a revision of mine. Here's what the new GUI looks like:

User generated image
The new version explicitly runs Excel on the temp file instead of whatever program owns the TXT file extension (you may need to change the Excel EXE location for your system). Here's a sample of what the Excel worksheet looks like after it loads the temp TXT file:

User generated image
Regards, Joe
AppendListFilesV2Rev2.ahk
Hi Joe,

I tested last version and it works. Thank you very much for this proposal it helps a lot specially this week that I am in a rush.

I just noticed something that I missed in the control of the GUI and that I have just identified following my tests.
When I don't report a folder and I click Ok the process is executed. I was wondering if there is an option to add a If (Not FileExist()) of FolderPath.
User generated image
Concerning the following:
>The simplest is to destroy the GUI (Gui,Destroy) before relaunching it.
Could you please show me how to proceed based on this GUI and then I will do it for the other GUIs already added in my AutoHotkey/Hotstring file.

Thank you very much for your help. Have an excellent week!

Regards,
Luis.
> I tested last version and it works.

Glad to hear it.

> When I don't report a folder and I click Ok the process is executed. I was wondering if there is an option to add a If (Not FileExist()) of FolderPath.

My suggestion is to display an error dialog if FolderPath is null or doesn't exist. The attached revision does that.

> Could you please show me how to proceed based on this GUI and then I will do it for the other GUIs already added in my AutoHotkey/Hotstring file.

The basic idea is to do a Gui,Destroy and a Return in all cases. The attached revision does that.

I improved your Edit box with a Browse button. You may still type or paste into the Edit box, but now you can click the Browse button and navigate to the folder via the Browse For Folder dialog. New GUI looks like this:

User generated image
And Browse dialog looks like this:

User generated image
Regards, Joe
AppendListFilesV2Rev3.ahk
Hi Joe,

Thank you very much for this proposal.

I started the testing phase and it works.

I will continue the testing phase for a while and I will keep you informed.

Regards,
Luis.
Joe,

I continued the testing phase and it works perfectly!

I was wondering if we can do the following adjustment:

Instead of having the default sentence (Select a folder by clicking Browse button on the right or type/paste into this field)
Have: EnvGet, UserProfileFolder, UserProfile
%UserProfileFolder%\ as a default folder and bellow the text zone:
"If you prefer select folder, please click on Browse button on the right or type/paste into this field."

Regards,
Luis.
ASKER CERTIFIED SOLUTION
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great Joe! Thank you very much for this! Another excellent GUI to my Autohotkey/Hotstring file. As Soon as I have access to my computer I will test it.
Thank you Joe, I tested and it works, perfectly. Last question on this. If I want to check the default folder reported in the zone bar to downloads can I proceed like this:

EnvGet,FolderPath,UserProfile
Gui,Add,Edit,vFolderPath cPurple w570 xm,%FolderPath%\Downloads

Open in new window


Nothing else to change?

Thank you for your help.
Hi Joe,

I send you attached last version that I added to my AutoHotkey/Hotstring file, I tested and it works.
If you could please let me know from your experts view if you see an error otherwise I will close the question.
AppendListFilesV2Rev5.ahk
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much for this catch.

I attached last version added to my AutoHotkey script for the record.

Following some tests, I have assigned your comments as a solution and as a result the question will be closed.
AppendListFilesV2Rev6.ahk
You're welcome, Luis. Last version looks perfect! Regards, Joe