topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday October 13, 2024, 8:00 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: Tally folder contents by file date  (Read 11463 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
DONE: Tally folder contents by file date
« on: September 22, 2018, 08:02 PM »
Suppose we have a folder with 100 files.

Objective is to create a text file with a list of dates and tally of those dates based on the 100 files.

Example:

2018-09-22 7
2018-09-19 8
2018-09-14 11
...
2018-09-3 1

Space separator between date and tally number.

No spaces within date.

Result can be sorted, or not.  Preference is to sort by date.

File name output should be same as folder name.  Plus .txt.

No need for GUI.  Command-line preferred, for creation of batch files (say, acting on lots of different folders).

Resultant .txt file should be created in same folder as executable, wherever user wants to keep that.

Parameter after executable should be folder path where files reside.

Example:

Tally_by_date.exe "C:\Program Files\My Program 123"

Use of piping might be okay.

Example:

Tally_by_date.exe "C:\Program Files\My Program 123" >> "My Program 123"

Any help greatly appreciated.

Thanks!

Nicholas Kormanik


wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,188
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #1 on: September 22, 2018, 09:42 PM »
And by date, do you mean cration date of the files, modification date, or something else?

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #2 on: September 22, 2018, 10:41 PM »
Creation date.

Thanks for asking!

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,188
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #3 on: September 22, 2018, 11:53 PM »
You can download it from https://my.pcloud.co...AxYJFJUz9dOpvmb4fLby

There are two files in the 75kb archive... TallyFiles.exe and CommandLine.dll.

Run TallyFiles to see the options, but they are

        [Option('d', "directory", Required = true, HelpText = "Directory to Scan")]
        [Option('f', "format", Required = false, HelpText = "Format of Date (Default yyyy-MM-dd)")]
        [Option('o', "output", Required = false, HelpText = "output filename (default name of directory, stored in directory)")]
        [Option('c', "compare", Required = false, HelpText = "compare to [C]reation Date or Last [A]ccess Date or Last [W]rite Date")]


So by default, if you run TallyFiles d=c:\test it will tally the files in c:\test and store them in c:\test\text.txt.  Formats are c# datetime formats (https://docs.microso...-time-format-strings), and if you specify an output filename, it will store it there. 

Requires .NET 4.5.2

Let me know if you have any questions.

Update: Added ability to use write and last access dates.



« Last Edit: September 23, 2018, 09:55 AM by wraith808, Reason: Update: Added ability to use write and last access dates. »

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #4 on: September 23, 2018, 04:37 AM »
I could use something like that too so here is an alternative implementation in AutoHotkey

Code: Autohotkey [Select]
  1.  
  2. ;Tally_by_date.ahk
  3. ;by nod5
  4.  
  5. ;- compile it and run from the command line with a folder path as parameter
  6. ;- outputs a date sorted tally of date created for all files in the input folder
  7.  
  8. ; example input: tally_by_date.exe "C:\this folder\folder"
  9.  
  10. ; example output: C:\this folder\folder\Tally_by_date -- 201809220631.txt
  11. ; with the content:
  12. ; 2018-07-23 9
  13. ; 2018-08-03 4
  14. ; ...
  15.  
  16. folder := A_Args[1]
  17.  
  18. if !InStr( FileExist(folder), "D")
  19.   ;not folder
  20.  
  21. f_array := []
  22.  
  23. ;loop over all files in folder, exclude folders and do not recurse
  24. Loop, Files, % folder "\*.*"
  25. {
  26.   ;get date in YYYY-MM-DD format
  27.   FormatTime, date_var, % A_LoopFileTimeCreated, yyyy-MM-dd
  28.   f_array[date_var] := f_array[date_var] ? f_array[date_var] + 1 : 1
  29. }
  30. For key, val in f_array
  31.   out .= key " " val "`n"
  32.  
  33. FileAppend, % out , % folder "\Tally_by_date -- " A_now ".txt"

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #5 on: September 24, 2018, 06:50 AM »
From here: Powershell version

TallyCreateDate.ps1
Code: PowerShell [Select]
  1. Get-ChildItem $args -File | Group {$_.CreationTime.ToString("yyyy-MM-dd")} | Sort Name | Format-Table Name,Count -auto

eg.

.\TallyCreateDate.ps1 "Z:\test folder" >"test folder.txt"

Output:

Code: Text [Select]
  1. Name       Count
  2. ----       -----
  3. 2015-02-02     1
  4. 2015-06-09     1
  5. 2015-06-28     1
  6. 2015-07-21     1
  7. 2015-08-29     1
  8. 2015-10-24     1
  9. 2015-12-16     1
  10. 2016-01-15     1
  11. 2016-05-27     1
  12. 2016-06-20     1
  13. 2016-07-10     4
  14. 2016-07-12     2
  15. 2017-11-01     1
  16. 2018-04-05     1
  17. 2018-04-14     4
  18. 2018-07-14     2
  19. 2018-08-03     1
  20. 2018-08-08     1
  21. 2018-08-10     1
  22. 2018-08-13     4
  23. 2018-08-14     1
  24. 2018-08-17     3
  25. 2018-09-19     1
  26. 2018-09-24     1
« Last Edit: September 24, 2018, 06:55 AM by 4wd »

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,543
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #6 on: September 24, 2018, 07:14 AM »
From here: Powershell version ...
Ohh...nice find.   :Thmbsup:

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #7 on: September 24, 2018, 07:19 AM »
From here: Powershell version ...
Ohh...nice find.   :Thmbsup:

The power of Google ;)

This'll do every sub-folder of the given folder with matching output names:
Code: PowerShell [Select]
  1. $folders = Get-ChildItem $args -Directory
  2. for ($i = 0; $i -lt $folders.Count; $i++) {
  3.   $file = $folders[$i].BaseName + ".txt"
  4.   Get-ChildItem $folders[$i].Fullname -File |
  5.     Group {$_.CreationTime.ToString("yyyy-MM-dd")} |
  6.     Sort Name |
  7.     Format-Table Name,Count -Auto |
  8.     Out-File -FilePath $file
  9. }
« Last Edit: September 24, 2018, 08:15 AM by 4wd, Reason: BAH! I goofed ... fixed »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #8 on: September 26, 2018, 12:57 AM »
wraith808, beautifully done.  Thanks a million.

TallyFiles -d "C:\Windows System Tools" -o "Windows System Tools.txt"

Two enhancement requests:

1.  Allow the default output file save location be to where TallyFiles.exe resides and is executed from (via batch file there) (instead of folder being acted upon, presently the default save location).

Thus, command would be merely:

TallyFiles -d "C:\Windows System Tools"

(and .txt extension would be added to "Windows System Tools")

2.  I specified "Creation Date."  Could we have the option of "Date Modified"?

You might already be allowing for this through your -c, --compare option.  But I don't understand how it works, if so.

Great job!

Thanks again.

Nicholas


highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 188
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #9 on: September 26, 2018, 04:07 AM »
My 2 cents...

TallyFiles.exe "path_1" "path_2" "path_X" [/fmt="yyyy-mm-dd" /date="c"]

- No dependencies
- It allows multiple paths in one call. If they contain spaces, double quotes are a necessity!
- Environment variables in paths are supported, e.g. "%windir%\Fonts"
- /fmt and /date are both optional (and can be used independently from each other)
- It should be clear that the same /fmt and /date values are used for all paths^^
- /fmt allows these elements:
  yyyy - 4 digit year
  yy   - 2 digit year
  mm   - 2 digit month
  dd   - 2 digit day
  hh   - 2 digit hour
  ii   - 2 digit minute
  ss   - 2 digit second
  The default is "yyyy-mm-dd"
- /date can be "c", "m" or "a" where "c" is the default

E.g.:
TallyFiles.exe "%windir%\Fonts"
will write a file named "Fonts.txt" into TallFiles.exe's location (in ascii format) with the creation date (sort method: ascending)

TallyFiles.exe "%windir%\Fonts" /date="m"
The same as above, this time with modified dates

etc.

The attachment contains a x86 and a x64 version...
« Last Edit: September 26, 2018, 10:11 AM by highend01 »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,188
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #10 on: September 26, 2018, 10:30 AM »
wraith808, beautifully done.  Thanks a million.

TallyFiles -d "C:\Windows System Tools" -o "Windows System Tools.txt"

Two enhancement requests:

1.  Allow the default output file save location be to where TallyFiles.exe resides and is executed from (via batch file there) (instead of folder being acted upon, presently the default save location).

Thus, command would be merely:

TallyFiles -d "C:\Windows System Tools"

(and .txt extension would be added to "Windows System Tools")

2.  I specified "Creation Date."  Could we have the option of "Date Modified"?

You might already be allowing for this through your -c, --compare option.  But I don't understand how it works, if so.

Great job!

Thanks again.

Nicholas




I can do the first easily... will update later today.  As far as the second, the -c is the way to do that.  Three properties on the FileInfo object in windows are: [C]reation Date or Last [A]ccess Date or Last [W]rite Date.

I know last write date is the last day it was written (i.e. modified) and the create date is pretty obvious.  I haven't been able to figure out how it computes last access date.  So to change your command line above. 

Code: Text [Select]
  1. TallyFiles -d "C:\Windows System Tools" -c W

And even currently, you don't have to put output; it infers it from the folder name.  You only have to specify that if you want a different name from the folder name.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #11 on: September 28, 2018, 07:29 PM »
Output file still ends up in 'acted-upon' folder.

Prefer output file to be created in folder where TallyFiles.exe resides.

Thanks!

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #12 on: September 28, 2018, 07:42 PM »
Curiously the -c W parameter gives some really early dates.  Not sure what it's doing.

Different from 'Date Modified'.

Prefer 'Date Modified' option, along with the default 'Date Created'.

Thanks!
« Last Edit: September 28, 2018, 08:10 PM by nkormanik »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,188
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #13 on: September 28, 2018, 09:22 PM »
I hadn't updated it yet; unfortunately, I've been a bit busy at work.  It is now updated to save in the run directory by default, though I did add another command line param:

Code: Text [Select]
  1. [Option('s', "savedir", Required=false, HelpText = "Save directory.  By default the file stored the in directory where tallyfiles is run")]

As far as the limitations of what it does with the dates, it's a limitation of the information that windows stores in the FileSystemInfo structure.

It has the following properties (and definitions)

FileSystemInfo.LastAccessTime: The time that the current file or directory was last accessed.

FileSystemInfo.CreationTime: Gets or sets the creation time of the current file or directory.

FileSystemInfo.LastWriteTime: Gets or sets the time when the current file or directory was last written to.
« Last Edit: September 28, 2018, 09:29 PM by wraith808 »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #14 on: September 29, 2018, 03:16 AM »
Beautiful job, wraith808.  Thanks very much.

Skwire, another winner.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: DONE: Tally folder contents by file date
« Reply #15 on: September 29, 2018, 03:20 AM »
Thanks also to:

Nod5
4wd
highend01

Terrific skills demonstrated.