Mireille Posted March 9, 2009 Posted March 9, 2009 Hi everyone! 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?
BlackScorpion Posted March 9, 2009 Posted March 9, 2009 Hi everyone! 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? 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.") ExitEndIf_ArrayDisplay($FileList,"$FileList")
Moderators Melba23 Posted March 9, 2009 Moderators Posted March 9, 2009 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Mireille Posted March 9, 2009 Author Posted March 9, 2009 Sorry for perhaps being a bit dense - it has been a long and rather tiring day. :-)And a rainy one, too 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.docc:\user\1\example.docc:\user\2\tolongforthisexample.docc:\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...
Authenticity Posted March 9, 2009 Posted March 9, 2009 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.
Moderators Melba23 Posted March 9, 2009 Moderators Posted March 9, 2009 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Spiff59 Posted March 9, 2009 Posted March 9, 2009 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,"????????.*)
BlackScorpion Posted March 10, 2009 Posted March 10, 2009 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 ==========================
Malkey Posted March 10, 2009 Posted March 10, 2009 (edited) 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 March 10, 2009 by Malkey
Spiff59 Posted March 10, 2009 Posted March 10, 2009 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.
Malkey Posted March 11, 2009 Posted March 11, 2009 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")
Spiff59 Posted March 11, 2009 Posted March 11, 2009 (edited) 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 March 11, 2009 by Spiff59
BlackScorpion Posted March 11, 2009 Posted March 11, 2009 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.
Ascend4nt Posted March 11, 2009 Posted March 11, 2009 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. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
Spiff59 Posted March 11, 2009 Posted March 11, 2009 (edited) 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 March 11, 2009 by Spiff59
Ascend4nt Posted March 11, 2009 Posted March 11, 2009 (edited) ... 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 March 11, 2009 by ascendant My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
/dev/null Posted March 12, 2009 Posted March 12, 2009 Hi everyone! 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? _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 *
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now