Jump to content

Recommended Posts

  • Moderators
Posted

You need to think about the format, and what you want it to be. If you go with an INI, what are you looking for? Different directories in different sections? All in one section? If you're going to put it all under one, you might as well write out to a flat text file. If you are going to split up different directories into different ini sections, you'll have to decide on the logic around how you split them.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted (edited)

Here's the workflow. I am trying to scan C:\ for folder name, once it's found pass the path to a variable, and capture the sub folders inside that with a stringTrimRight 3 places to remove the extension and save the names of each sub folder to an ini. would it be easier to read a path from a text file or ini?

Edited by aa2zz6
  • Moderators
Posted

I would say in your case just a text file. So you could use _FileWriteFromArray to accomplish this.

My next question would be why you need to output to a text file at all? Are you simply wanting a text file to show you the sub directories (which would make sense), or are you taking action on those directories (add, delete, etc.)? If you are doing everything within a single script, it would be better to simply work from the array and skip the text file altogether.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted (edited)

I was hoping we could export the sub directory names so we could view them in some type of text file. We would probably manually delete the folders though. A sub directory folder list would be great to generate. 

Edited by aa2zz6
Posted

Also beware that extensions may be present or not and aren't limited to 3 chars.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)

Just looking for folders. If I remove the front part of the path and the extension I figured it would be easier to read. I could include the file path at the top. Do people normally leave the entire path and extension on?

Edited by aa2zz6
Posted

I don't get it: if one folder is named "my folder.which.has a.weird.Җѳѣҫәӄ.extension" how things are going to work if you truncate the name in bold in any manner?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)

jchd, sorry, you're right. I forgot that folders don't have extensions. *Feeling very stupid* :\  Now I have to figure out how to remove everything before the last slash and just show the names. I will include the full directory at the top of the text file I think.

 

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

Global $txtFile = @ScriptDir & "\"
Global $mainDirectory = "MainfilePath.txt"
Global $subDirectory = "SubDirectories.txt"

; Find the main directory & save path to txt
$aArray = _FileListToArrayRec("C:\", "Desktop10.6", 2, 1, 1, 2)
_FileWriteFromArray ( $txtFile & $mainDirectory, $aArray)
_FileWriteToLine($txtFile & $mainDirectory,1,"", 1)

; Call the full path to a variable
$NumberOfLines = _FileCountLines($txtFile & $mainDirectory)
$ReadLastLine = FileReadLine($txtFile & $mainDirectory, $NumberOfLines)
$readPath = $ReadLastLine
ConsoleWrite($readPath)

; Read sub directories inside the main folder and save them to another txt file
Local $aFileList = _FileListToArray($readPath, Default, $FLTA_FOLDERS, True)
;_ArraySort($aFileList)
;_ArrayDisplay($aFileList, "$aFileList")
_FileWriteFromArray ( $txtFile & $subDirectory, $aFileList)
_FileWriteToLine($txtFile & $subDirectory,1,"", 1)

;

sub directories -

C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcGlobeData
C:\Program Files (x86)\ArcGIS\Desktop10.6\arcpy
C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcToolbox
C:\Program Files (x86)\ArcGIS\Desktop10.6\bin
C:\Program Files (x86)\ArcGIS\Desktop10.6\ColorProfiles
C:\Program Files (x86)\ArcGIS\Desktop10.6\com
C:\Program Files (x86)\ArcGIS\Desktop10.6\DatabaseSupport
C:\Program Files (x86)\ArcGIS\Desktop10.6\Documentation
C:\Program Files (x86)\ArcGIS\Desktop10.6\Geocode
C:\Program Files (x86)\ArcGIS\Desktop10.6\GraphTemplates
C:\Program Files (x86)\ArcGIS\Desktop10.6\GridTemplates
C:\Program Files (x86)\ArcGIS\Desktop10.6\help
C:\Program Files (x86)\ArcGIS\Desktop10.6\java
C:\Program Files (x86)\ArcGIS\Desktop10.6\lib
C:\Program Files (x86)\ArcGIS\Desktop10.6\License
C:\Program Files (x86)\ArcGIS\Desktop10.6\locale
C:\Program Files (x86)\ArcGIS\Desktop10.6\Locators
C:\Program Files (x86)\ArcGIS\Desktop10.6\MapTemplates
C:\Program Files (x86)\ArcGIS\Desktop10.6\Metadata
C:\Program Files (x86)\ArcGIS\Desktop10.6\NetworkAnalyst
C:\Program Files (x86)\ArcGIS\Desktop10.6\PackageTemplates
C:\Program Files (x86)\ArcGIS\Desktop10.6\PDFL
C:\Program Files (x86)\ArcGIS\Desktop10.6\pedata
C:\Program Files (x86)\ArcGIS\Desktop10.6\plotters
C:\Program Files (x86)\ArcGIS\Desktop10.6\Reference Systems
C:\Program Files (x86)\ArcGIS\Desktop10.6\resources
C:\Program Files (x86)\ArcGIS\Desktop10.6\Routing
C:\Program Files (x86)\ArcGIS\Desktop10.6\Schematics
C:\Program Files (x86)\ArcGIS\Desktop10.6\SearchResources
C:\Program Files (x86)\ArcGIS\Desktop10.6\Styles
C:\Program Files (x86)\ArcGIS\Desktop10.6\Support
C:\Program Files (x86)\ArcGIS\Desktop10.6\TemplateData
C:\Program Files (x86)\ArcGIS\Desktop10.6\Templates
C:\Program Files (x86)\ArcGIS\Desktop10.6\TilingSchemes
C:\Program Files (x86)\ArcGIS\Desktop10.6\TimeZones
C:\Program Files (x86)\ArcGIS\Desktop10.6\Tools
C:\Program Files (x86)\ArcGIS\Desktop10.6\Utilities
C:\Program Files (x86)\ArcGIS\Desktop10.6\XmlSchema

 

Edited by aa2zz6
Posted (edited)

You want just the file name from the path?

$filename = FileGetName("C:\aka\dsss\filesname")

Func FileGetName($sPath)
    Return StringMid($sPath, StringInStr($sPath, "\", 0, -1) + 1)
EndFunc   ;==>FileGetName

Here's the path without file name:

Func FileGetFolder($sPath)
    $pathreturn = StringMid($sPath, 1, StringInStr($sPath, "\", 0, -1))
    Return $pathreturn
EndFunc   ;==>FileGetFolder

 

Edited by Xandy
Posted

Ahem, directories may carry an extension (or not), just like files. In your example, 6 can be considered an extension of the parent folder of C:\Program Files (x86)\ArcGIS\Desktop10.6\Reference Systems

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...