usustarr Posted January 18, 2016 Posted January 18, 2016 I have a folder structure with variable depth. For ex, C:\folder1\folder2\folder3\test.txt C:\folder1\testTwo.txt C:\folder1\folder2\somefiletest.txt I have a need to get rid of the *.txt file from this folder path. So for example, for above paths, I want to see following, C:\folder1\folder2\folder3\ C:\folder1\ C:\folder1\folder2\ How do I write AutoIt script to do this? I am pretty new to AutoIt and not good with RegEx at all. Please help me out, thank you
kylomas Posted January 19, 2016 Posted January 19, 2016 usustarr, Is this what you are looking for? #include <array.au3> local $aFiles = [ _ 'C:\folder1\folder2\folder3\test.txt', _ 'C:\folder1\testTwo.txt', _ 'C:\folder1\folder2\somefiletest.txt'] _arraydisplay($aFiles) for $i = 0 to ubound($aFiles) - 1 $aFiles[$i] = StringRegExpReplace($aFiles[$i],'(.*\\).*','$1') Next _arraydisplay($aFiles) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
ViciousXUSMC Posted January 19, 2016 Posted January 19, 2016 (edited) And the whole "don't use regex unless you have too" rule. Here is a alternative. #include <array.au3> local $aFiles = [ _ 'C:\folder1\folder2\folder3\test.txt', _ 'C:\folder1\testTwo.txt', _ 'C:\folder1\folder2\somefiletest.txt'] _arraydisplay($aFiles) for $i = 0 to ubound($aFiles) - 1 $iPos = StringInStr($aFiles[$i], "\", 0, -1) $aFiles[$i] = StringLeft($aFiles[$i], $iPos) Next _arraydisplay($aFiles) As for your list of files, I am unsure if you have them already, but I assume no. So something like FileListToArrayRec() with a *.txt filter would work. Then you would want to clean out the duplicates. Edited January 19, 2016 by ViciousXUSMC
jguinch Posted January 19, 2016 Posted January 19, 2016 or StringRegExpReplace($aFiles[$i],'[^\\]+$','') Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
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