How to make a list of files not using Mp3tag - and add a datestamp to it?

I need to make a list of all of the files for ma folder that has many sub-folders- in which there are many files


With a BAT like this

tree P:\YouTube /f > "C:\Archive\File List.txt"

I get a File List.txt in folder Archive on drive C. It is the minimum I need


The problem with this method are:

A] The TXT file gets overwritten every time I execute the BAT. I can work around that problem with a backup software, but I would prefer to have multiple TXT files in that folder, each with a date and [also maybe time] in its name when the list was created. So for example I would have something like File List 2019-11-01 12_00_00.txt, File List 2019-11-15 16_05_00.txt, ``File List 2020 01 17 23_00_06.txt` etc.

B] The TXT files have a nice graphical form of a tree. But diacritic signs are all massed up. And adding parameter /a [using ASCII instead of extended characters, whatever those extended ones are] does not fix that, but [if I am not mistaken] only changes the signs used for the drawing of the tree


So does anyone know what else I can use? To add the date and time to the TXT file and see in it all of the characters

see this external site:

Have a look at powershell as you are using Windows

Open a powershell window and navigate to your P:\YouTube directory
then run

Get-ChildItem -Recurse | Write-Output | Tee-Object -FilePath $("P:\YouTube\File List - "+[datetime]::Now.ToString("yyyy-MM-dd-HH-mm-ss")+".txt") | Out-Null

The above is all one line

They seem to get this done there, although it seems to be complicated

And because there is still the problem of diacritic sings, for now I will leave it alone

Nice, as the sub-folders are visually separated on the list and all the diacritic signs are present. But I also get all that excess of information in front of each Name, i.e. Mode, LastWriteTime, Length. And I would not know how to remove all of that info If I had to actually use that list. [I tried pasting it into spreadsheet in Excell but could not get them into separate columns]


So I tried coming up with a different code

Get-ChildItem -Recurse -Include *.* -Name | Write-Output | Tee-Object -FilePath $("P:\YouTube\File List "+[datetime]::Now.ToString("yyyy-MM-dd hh_MM_ss")+".txt") | Out-Null

With it I get a list, but this time it that has no visual separation between folders, which is a drawback. It has folders and sub-folders in front of Names, so I know I will be able to make a usage of such list- but it still would require then a lot of hand work from me if I actually had to use it. [The purpose of this list to be able to know what I want to watch again in the future in case if all of my backup copies will be inaccessible and my YouTube account will also be of no use or inaccessible]


And if I use a code like that

Get-ChildItem -Recurse -Include *.* | Format-Table name -hidetableheaders | Write-Output | Tee-Object -FilePath $("P:\YouTube\File List "+[datetime]::Now.ToString("yyyy-MM-dd hh_MM_ss")+".txt") | Out-Null

then the during the generation of the list it removes the directories thus turning the full-paths into just filenames and also not showing any of the excess information [Mode, LastWriteTime, Length]. Having just Names in a single line is exactly what I am after, but not having block of lines [i.e. content of directories] somehow separated and described with names of directories simply makes such list almost completely useless [as I do not know which video comes from which youtube channel]


So what I need is something that has a space structure like in the code presented by @Spider099 pider099 but limited in information to just the directories / sub-folders paths and the name filenames within each of them; some kind of combination of the first and the third code

Can it be done within PowerShell?

Yes it can
Try this - gives "path" then file Name

Get-ChildItem -Recurse -Include . | Format-Table directory, name -hidetableheaders | Write-Output | Tee-Object -FilePath $("m:\Music\File List "+[datetime]::Now.ToString("yyyy-MM-dd hh_MM_ss")+".txt") | Out-Null

if thats not what you want

Then show an example!

So let us start from the beginning

[The location of the file to be produced is now S:\Data]


APPROACH-A

The BAT version
tree P:\YouTube /f /a> "S:\Data\File List.txt"
produces a list like this:

|
+---Channel A
|       Some file 1.mp4
|       Some file 2.mp4
|       Some file 3.mp4
|      
+---Youtuber X
|   |   Some file 1.mp4
|   |  
|   \---Videos for editing
|       |                 Some file 1.mp4
|       |                 Some file 2.mp4
|       |
|       \---Material edited already
|                                  Some file 1.mp4
|
+---Youtuber YY
|       Some file 1.mp4
|
+---Youtuber ZZZ
|       Some file 1.mp4
|       Some file 2.mp4
|

It has pretty much a perfect form

The problem with this solution is that diacritic signs are messed up on such list; and that the TXT file does not have a date and time inserted to the end of its name


APPROACH-B

My first power shell commands

Get-ChildItem -Recurse -Include *.* -Name | Write-Output | Tee-Object -FilePath $("S:\Data\File List "+[datetime]::Now.ToString("yyyy-MM-dd hh_MM_ss")+".txt") | Out-Null

produces a list like this:

Channel A\Some file 1.mp4
Channel A\Some file 2.mp4
Channel A\Some file 3.mp4
Youtuber X\Some file 1.mp4
Youtuber X\Videos for editing\Some file 1.mp4
Youtuber X\Videos for editing\Some file 2.mp4
Youtuber X\Videos for editing\Material edited already\Some file 1.mp4
Youtuber YY\Some file 1.mp4
Youtuber ZZZ\Some file 1.mp4
Youtuber ZZZ\Some file 2.mp4

It is usable but in order for me to have a pure list of filenames, I would have to delete all that is before every \ sign; but paradoxically at the same time I would have to preserve name of folders in order to know where they came from


APPROACH-C

My second power shell commands

''Get-ChildItem -Recurse -Include . | Format-Table name -hidetableheaders | Write-Output | Tee-Object -FilePath $("S:\Data\File List "+[datetime]::Now.ToString("yyyy-MM-dd hh_MM_ss")+".txt") | Out-Null''

produces a list like this:

Some file 1.mp4
Some file 2.mp4
some file 3.mp4
Some file 1.mp4
Some file 1.mp4
Some file 2.mp4
Some file 1.mp4
Some file 1.mp4
Some file 1.mp4
Some file 2.mp4

Which is completely useless. The only advantage of it is that the TXT has the date and time at its end [just like in case of APPROACH-B and APPROACH-D]


APPROACH-D
The new power shell commands

Get-ChildItem -Recurse -Include *.* | Format-Table directory, name -hidetableheaders | Write-Output | Tee-Object -FilePath $("S:\Data\File List "+[datetime]::Now.ToString("yyyy-MM-dd hh_MM_ss")+".txt") | Out-Null

made from the latest suggestion of @Spider099 produces a list like this:

Channel A                                             Some file 1.mp4
Channel A                                             Some file 2.mp4
Channel A                                             Some file 3.mp4
Youtuber X                                            Some file 1.mp4
Youtuber X\Videos for editing                         Some file 1.mp4
Youtuber X\Videos for editing                         Some file 2.mp4
Youtuber X\Videos for editing\Material edited already Some file 1.mp4
Youtuber YY                                           Some file 1.mp4
Youtuber ZZZ                                          Some file 1.mp4
Youtuber ZZZ                                          Some file 2.mp4

For me this is usable and even has some visual perks which might come in handy depending on what and how I will be doing with this


But the perfect solution would be a list looking like in APPROACH-A but with various diacritic and unusual signs being retained properly; and with date and time added to end to end of filename of the TXT file

Would this was to be done with a BAT or a PS1 file - it would have [I suppose] no difference to me. [Although for now I have failed at turning those Power Shell commands into PS1 files, that could be executed from any place on a drive

add lastwritetime after name and before hide....

so
Get-ChildItem -Recurse -Include . | Format-Table directory, name, lastwritetime -hidetableheaders
then add the rest of Approach-d

this will add the date and time of the file to the output as the last column
@Zerow

Perhaps you have to modify the codepage prior to executing the tree command.
Open a shell and execute the command
chcp
to find the current codepage. For Western European PCs this should be 850
But perhaps 855 (kyrillic) or 866 (Russian) are better.
see e.g. wikipedia on the codepage:


Once you have found whether changing the codepage would help, add the changing command to the batch job.

You mean that it will insert date and time inside the file? If yes- than something is wrong, as it does not

APPROACH-D MODIFIED:
Get-ChildItem -Recurse -Include *.* | Format-Table directory, name, LastWriteTime -HideTableHeaders | Write-Output | Tee-Object -FilePath $("S:\Data\File List "+[datetime]::Now.ToString("yyyy-MM-dd hh_MM_ss")+".txt") | Out-Null


And what I noticed: the date at the of file is correct but the time is wrong; even without that newLastWriteTime addition. The time is an hour late. Then the correct hour starts to appear at the end of new files created repeatedly but the later a file is created, then the lower value in seconds it gets. Then the correct hour starts to appear the seconds start to go in the right way and in accordance to the OS clock- but the minutes are stuck at the same one


And also the long filenames are truncated with a ... indicator. The APPROACH-A [via BAT script] does not seem to create such problem

I have Active code page: 852 which is suppose to be a proper one for me

So I should not be getting "glitches" but proper diacritic signs in my TXT files created with BATs?

Cant see whats difficult with this - you are adding an extra column
As for the times being wrong - thats something up with your PC
But as you do lots of modifications - its probably something you have set somewhere

Anyway - i am bored with this now - you have a few options - which you can modify to try and get what you want - or use Google etc

See ya

I have found the overall perfect solution, going around issues with code page - the APPROACH-M, where M means mashup


Apparently it is possible to invoke Command Line codes within PowerShell. And so when being in PowerShell window with a simple code like this

Invoke-Expression "tree K:\YouTube /f" | Out-File "S:\Data\YouTube List.txt"

I create in the Data folder that TXT holding a nice visual tree displaying all of the files from that YouTube folder and its subfolders. And the filenames are not truncated in any way plus they display all of the diacritic signs correctly

So problem is solved? Not untirely


Unfortunately there is the issue of running PS1 scripts themselves from files. If I am not mistaken, as a supposed security measure the mouse double left click / the Open entry from shell menu by default opens PS1 file in Notepad. And so in order to really run them the Run with PowerShell entry from the shell menu must be chosen [instead of Open]. That can be of course changed by navigating in the Registry to

Computer\HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command

and changing the Value data there from

"C:\Windows\System32\notepad.exe" "%1"

to

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "%1"

[or alternatively making this permanent association by using the Open with option available at the shell menu]

But of course it could not be possibly that simply. Because after changing in the operating system the meaning of Open for PowerShell, that PowerShell now stops creating the TXT file at all, informing that

C:\Program : The term `C:\Program` is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
A line:1 char:1
+C:\Program Files Expanded/YouTube List.ps1
+ ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound" (C:Porogram:String) [], CommandNotFoundException
    + FullyQualifiedErrorId :</b> **`CommandNotFoundException`

[That C:\Program Files Expanded\YouTube List.ps1 is where the file with the script is residing]

So right now for me it is either [by default] impossible to run PS1 scripts in a convenient way i.e. in form of files from their shortcuts [because double clicking LNK file will open Notepad thus merely show an evoked script]; or [after de-associating PS1 files with Notepad] it is impossible to run PS1 scripts in form of files at all [because PowerShell tries to read the path to them as some kind of a command]



So there are probably three workarounds to this:

WORKAROUND-1] Do not tamper with how PS1 files are being run [i.e. leave the default behavior] but create a BAT file that will run that particular PS1 file

In theory in CMD this should work

powershell.exe -command "Invoke-Expression "tree K:\YouTube /f" | Out-File "S:\Data\YouTube List.txt""

While when such BAT is executed it flashes the error message

Invoke-Expression : A positional parameter cannot be found that accepts argument 'K:\YouTube'.
At line:1 char:1
+ Invoke-Expression tree K:\YouTube /f | Out-File S:\Data\YouTube List. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
    + CategoryInfo          : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand

And when the same code is executed directly form the prompt line of the CMD window, a pop up windows appears saying

This app can't run on your PC

after closing which it is followed by message

Access is denied.

written in the CMD window


WORKAROUND-2] After de-associating PowerShell with Notepad, fix it somehow to read the path as path

It is mind staggering why and how changing

Computer\HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command

makes the software itself read paths within scripts as commands


WORKAROUND-3] Use some third party software that will turn PS1 file into EXE

I am afraid that similar problems will arise, with paths being read as commands. Or there ill be some others issues


As for the time parameter issue

I tried changing the datetime / yyyy-MM-dd hh_MM_ss to date / yyyy-MM-dd and time / hh_MM_ss while also tampering with the other portion of the code, but I gave it up this, as I am not a programmer. I can operate with just one TXT being created and then overwritten over and over again [as I make multiple copies of that file with other means]

sigh!
use this example instead for you bat file - so PS can evaluate the command properly
powershell.exe -command "Invoke-Expression 'tree M:\music /f' | Out-File 'm:\music\test.txt'"

use single quotes and double quotes only around the whole expression after -command
single and double quotes are evaluated differently in PS

and as you dont understand why PS scripts are not set to execute like bat files do then dont play around with the registry settings as you will get in a mess as you have.

Hence why you were getting errors and unexpected results , besides you commands were wrong

To sum up


In command prompt of the PowerShell window this code works

Invoke-Expression "tree K:\YouTube /f" | Out-File "S:\Data\YouTube List.txt"

and it can be also saved as a PS1 file


And when reworked to

powershell.exe -command "Invoke-Expression 'tree K:\YouTube /f' | Out-File 'S:\Data\YouTube List.txt'"

it can be inserted successively into a BAT file


Both of the above will result in creation of TXT file looking like this

K:\YOUTUBE     
├───Channel A
│       Some file 1.mp4
│       Some file 2.mp4
│       Some file 3.mp4
│      
├───Youtuber X
│   │   Some file 1.mp4
│   │  
│   └───Videos for editing
│       │   Some file 1.mp4
│       │   Some file 2.mp4
│       │  
│       └───Material edited already
│               Some file 1.mp4
│              
├───Youtuber YY
│       Some file 1.mp4
│      
├───Youtuber ZZZ
        Some file 1.mp4
        Some file 2.mp4

with very long filenames and diacritic signs being retained; and without the need of making any changes to the operating system [at least in case of Windows 10]


Thank you all for the time put into helping me with this task

1 Like