Jump to content
Sign in to follow this  
Mireille

count length of filenames in (sub-)folders

Recommended Posts

Mireille

Hi everyone! :unsure:

First of all I want to say "Hi" to all users in this forums! Seems to be a really big community!

I've searched and searched regarding the topic above - is there really no way to do it with AutoIt or am I just to stupid to search the right way? :P

Share this post


Link to post
Share on other sites
BlackScorpion

Hi everyone! :unsure:

First of all I want to say "Hi" to all users in this forums! Seems to be a really big community!

I've searched and searched regarding the topic above - is there really no way to do it with AutoIt or am I just to stupid to search the right way? :P

you can use _FileListToArray --- please refer to the AutoIt UDF help file

#Include <File.au3>

#Include <Array.au3>

$FileList=_FileListToArray(@DesktopDir)

If @Error=1 Then

MsgBox (0,"","No Files\Folders Found.")

Exit

EndIf

_ArrayDisplay($FileList,"$FileList")

Share this post


Link to post
Share on other sites
Melba23

Mireille,

First, welcome to the AutoIt forums.

Now, could you please clarify what exactly you want - is it the number of characters in the names (i.e. file.ext would give an answer of 8) or something else?

Sorry for perhaps being a bit dense - it has been a long and rather tiring day. :-)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Mireille

Sorry for perhaps being a bit dense - it has been a long and rather tiring day. :-)

And a rainy one, too :P

I want to know which filenames (without the extension) in a given folder and the subfolders are longer than e.g. 8 charakters.

Example:

c:\user\1\test.doc

c:\user\1\example.doc

c:\user\2\tolongforthisexample.doc

c:\user\2\12345.doc

--> how can I find out which of the files in the folder "user" is to long? Do you understand what I mean? I'm sorry for my english - I'm not a native speaker and still learning...

Share this post


Link to post
Share on other sites
Authenticity

Use a recursive search (search the forum, it has been asked for many times) and test each file, or folder, if it's filename without the extension part is longer than 8 characters.

Share this post


Link to post
Share on other sites
Melba23

Mireille,

As Authenticity has pointed out, you first need a recursive file search - you can find a number of these in this thread. Once you have your list of files, you need to use StringSplit to separate the filename from the path and then the extension from the name itself. Finally you need to use StringLen to measure the number of characters in the name.

You can find all the details of the functions I mentioned in the help file - so go and have a try at coding it yourself - because no-one here is too keen on helping the "code-it-for-me" posters. ;-)

If you are new to coding, reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here. Using the Search facility is also a good tip as there is a pretty good chance your question, or parts of it, has been asked before. Look for the "Search" button to the right in the title bar .

So as I said, go and try to do something on your own - if you have problems, come back and show us your code so we can help.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Spiff59

If what you're actually doing is throwing out the names longer than 8, and keeping those 8 or less (and you don't have to report or list the rejects), then you could do it with a one-liner:

$FileList=_FileListToArray(@DesktopDir,"????????.*)

Share this post


Link to post
Share on other sites
BlackScorpion

This should help you out -- I had to do a dos cmd dir /aa bla bla bla to get the directory and subdirectory names

just change the $filepath to the directory you want to check....

=========== chop here ======================

#include <File.au3>

#include <Array.au3>

$workingDir="c:\"

$filePath="c:\windows\temp\*.*"

$tmpFile="files.txt"

Dim $queriedFiles

;#### get all filenames and subdirectories without returning subdirectory names!

RunWait(@ComSpec & " /c " & "dir /aa /b /s " & $filePath & " > " & $tmpFile, $workingDir)

_FileReadToArray( $workingDir & "\" & $tmpFile, $queriedFiles )

For $i = $queriedFiles[0] to 1 step -1

$tmpString = StringSplit( $queriedFiles[$i], "\" )

if StringLen($tmpString[$tmpString[0]]) < 14 Then _ArrayDelete( $queriedFiles,$i)

Next

;#### delete temp file and display results

FileDelete( $workingDir & "\" & $tmpFile )

_ArrayDelete( $queriedFiles,0 )

_ArrayDisplay($queriedFiles,"your long filenames")

=========== and here ==========================

Share this post


Link to post
Share on other sites
Malkey

If what you're actually doing is throwing out the names longer than 8, and keeping those 8 or less (and you don't have to report or list the rejects), then you could do it with a one-liner:

$FileList=_FileListToArray(@DesktopDir,"????????.*)
Spiff59

I thought this was a good idea, but it does not work.

So, I share my new found knowledge with you.

From help file under FileFindFirstFile about wildcards.

"You can use only one wildcard in the filename part or in the extension part i.e. a*.b?.

?? seems equivalent to * (not described in Microsoft documentation).

When using a 3-char extension any extension starting with those 3 chars will match, .e.g. "*.log" will match "test.log_1". (not described either in Microsoft dosumentation)."

dosumentation?? - Freudian slip in help file.

Edit: From DOS documentation, this can be done.

According to the EMBEDDED DOS-ROM Users Manual, "B???????.???", will return all files that start with a

letter 'B'.

Edited by Malkey

Share this post


Link to post
Share on other sites
Spiff59

Malkey -

Yeah, I saw that in that in the help documentation...

The trouble is, it's not true.

"?" seems to represent zero or one character, whether used in a CMD prompt, or passed to _FileListToArray as the wildcard mask. "????????.*" does return all files with 8 characters or less. At least that's the case with XP and Vista... am not sure I could find a WIn98 machine to test if I tried.

I guess the help documentation needs to be corrected.

Share this post


Link to post
Share on other sites
Malkey

Spiff59

The results from the below wild card test script run on my xp.

8 question marks - All files of any length are returned, That is, returns file names with lengths greater than, equal to, or less than 8.

More than 8 question marks - Again, all files of any length are returned.

7 question marks or less - The number of question marks determine the maximum file name length and returns all files with that maximum file name length and less.

I am thinking that this behaviour of the 8 wild card limit returning all files, on my system anyway, may be a flow-on effect of the DOS and early Windows systems requiring files to follow the 8.3 file name convention.

From your last post, it appears my results are peculiar to my machine.

#include <File.au3>
#include <Array.au3>

$sWildCards = "????????.*"

$FileList = _FileListToArray("C:\Program Files\AutoIt3", $sWildCards)
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf

Dim $FileLen[UBound($FileList) + 1][2]

For $ndx = 0 To UBound($FileList) - 1
    $FileLen[$ndx][0] = $FileList[$ndx]

;Length of filename without dot extension.
    $FileLen[$ndx][1] = StringLen(StringRegExpReplace($FileList[$ndx], "\..*$", "")) & "  Without .ext"
;ConsoleWrite(StringRegExpReplace($FileList[$ndx],  "\..*$", "") & @CRLF)
Next

$FileLen[UBound($FileLen) - 1][0] = $sWildCards
$FileLen[UBound($FileLen) - 1][1] = StringLen(StringRegExpReplace($sWildCards, "\..*$", "")) & "  Without .ext"

_ArrayDisplay($FileLen, "$FileListLength")

Share this post


Link to post
Share on other sites
Spiff59

Malkey -

I'm going to have to agree with you, at least regarding my home machine, which is XP Pro SP3.

Question marks represent zero or one character up to 7 question marks, beyond that ????????.* acts like *.*.

I could swear when I ran a few tests at work on another XP SP3 machine that 8 ?'s returned a smaller file list than *.*.

I'll have to check tomorrow and see if that's the case, if so it must be some environment or registry setting. Or possible different versions of some .dll? It's also possible that I'm nuts and only went as high as seven in my quick tests.

In either case, what the help file states is far from actuality and probably ought to be corrected.

typo

Edited by Spiff59

Share this post


Link to post
Share on other sites
BlackScorpion

The code I provided will work fine, no limit to ??????, I actually tested it before submitting it. Oh, and its longer than a 1 liner that doesn't work. It will also parse all of c:\ and subdirectories if you so desired, not just a single directory.

I provide solutions, not more problems.

Share this post


Link to post
Share on other sites
Ascend4nt

The code I provided will work fine, no limit to ??????, I actually tested it before submitting it. Oh, and its longer than a 1 liner that doesn't work. It will also parse all of c:\ and subdirectories if you so desired, not just a single directory.

I provide solutions, not more problems.

Here's one problem: DOS Dir commands will never return Unicode filenames properly.

As far as ? -> the logic is it should return one character per ?, and * = any number of chars, with special circumstances. The _DOSWildcardsToPCRegEx function in my sig. will allow a person to use a *.* search and filter out unmatching strings.

Share this post


Link to post
Share on other sites
Spiff59

The code I provided will work fine, no limit to ??????, I actually tested it before submitting it. Oh, and its longer than a 1 liner that doesn't work. It will also parse all of c:\ and subdirectories if you so desired, not just a single directory.

I provide solutions, not more problems.

Sheesh, here 2 days and already copping an attitude?

Malkey had already pointed out (in a civilized manner) that the ? wildcard didn't seem to perform above 7 characters.

Last night, I replied that, rechecking, I was getting that same result. I don't think your input was very useful at this point.

3 of your total 4 posts are in this thread and I did not see anyone trashing you about the first one, that had little to do with the OP's request. As to your second 'working' script, it only returns files with the archive attribute set, it only returns filenames > 9 , not 8 (yes, easily fixed, had it been tested), it assumes a 3-character file extension, other than that will include or exclude files from the list incorrectly, and as the last post pointed out, it blows up if you include something like "\Program Files\" in your pathname. I also question why one would voluntarily add additional disk access unnecessarily. I/O's via mechanical hardware are about as inefficient as you can get.

Let's both live by the following rule:

=================== chop here =====================

/* Be civil */

=================== and here ======================

typos

Edited by Spiff59

Share this post


Link to post
Share on other sites
Ascend4nt

... and as the last post pointed out, it blows up if you include something like "\Program Files\" in your pathname.

Actually, Unicode is a different matter altogether than spaces in a file path. That can easily be overcome with double-quotes. You are right about the attribute bit though. IT should read "/a:-", which will include all types of files, any attributes.

Including /X (without /B) would allow picking up short-names which would circumvent the Unicode name problem, but that requires output to be parsed, in addition to requiring that short-names are turned on for the file system (typically it is, but it's possible to be turned off)

*edit: just to note - to exclude folders from the list and still get all files with all attrib's, you can use "/a:-d"

Edited by ascendant

Share this post


Link to post
Share on other sites
/dev/null

Hi everyone! :unsure:

First of all I want to say "Hi" to all users in this forums! Seems to be a really big community!

I've searched and searched regarding the topic above - is there really no way to do it with AutoIt or am I just to stupid to search the right way? :P

_FileChangeRecursive() with the worker function below:

Link: http://www.autoitscript.com/forum/index.ph...c=40542&hl=

Calling syntax and Worker:

#include "_FileChangeRecursive.au3"
#include <file.au3>

$retval = _FileChangeRecursive("D:\","*.pdf",-1,"_FileNameLen",8)

func _FileNameLen($filepath,$len)

    Local $szDrive, $szDir, $szFName, $szExt
    $TestPath = _PathSplit($filepath, $szDrive, $szDir, $szFName, $szExt)
    
    If StringLen($szFName) > $len Then
        ConsoleWrite("Name longer than " & $len & ": " & $filepath & @CRLF)
    Endif
    
endfunc

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.