Jump to content

How to look in sub directories?


Recommended Posts

I am trying to rename PDF's inside our 2015 Archive folder but I'm not sure how to access each sub folder.

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>



$FileList = _FileListToArray("C:\Users\jnmiller\Desktop\2015 Archive")
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf

For $i = 1 To $FileList[0]
    MsgBox(0, $i, $FileList[$i])

    ; Find pdf's in folders
    $sFileOld = "C:\Users\jnmiller\Desktop\2015 Archive\" & "\*.pdf*"

    ; Get folder name
    $renamePDF = StringSplit(@ScriptDir,"\",0)

    ; Change pdf name to match folder name
    FileMove($sFileOld, $renamePDF[$renamePDF[0]] & ".pdf")

    ; Create variable for new dest
    Local $newDest = "C:\Users\jnmiller\Desktop\Store PDF Files"
    ; Move pdf's to NEO Service Line Scans
    FileMove($renamePDF[$renamePDF[0]] & ".pdf",$newDest,0)
Next

 

img.png

Link to comment
Share on other sites

6 hours ago, Andreik said:

You can use _FileListToArrayRec().

Hi, I am having trouble understanding this function. I am using the _FileListToArrayRec function and it's listing the pdf's in an _ArrayDisplay but it's not able to rewrite the pdf's to another file like the _FileListToArray function before.

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

Global $aArray = _FileListToArrayRec("C:\Users\jnmiller\Desktop\test123", "*.pdf", _
    $FLTAR_FILES+$FLTAR_NOSYSTEM+$FLTAR_NOHIDDEN, _
    $FLTAR_RECUR, $FLTAR_FASTSORT, $FLTAR_FULLPATH)

; Display Results
; _ArrayDisplay($aArray, " Results")

;$FileList = _FileListToArray("C:\Users\jnmiller\Desktop\test123")


If @error = 1 Then
    ;MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf

For $i = 1 To $aArray[0]
    ;MsgBox(0, $i, $FileList[$i])

    ; Find pdf's in folders
    ;$sFileOld = "C:\Users\jnmiller\Desktop\test123\" & "\*.pdf*"

    ; Get folder name
    $renamePDF = StringSplit(@ScriptDir,"\",0)

    ; Change pdf name to match folder name
    FileMove($aArray, $renamePDF[$renamePDF[0]] & ".pdf")

    ; Create variable for new dest
    Local $newDest = "C:\Users\jnmiller\Desktop\Store PDF Files"
    ; Move pdf's to NEO Service Line Scans
    FileMove($renamePDF[$renamePDF[0]] & ".pdf",$newDest,0)
Next

 

Edited by aa2zz6
Spelling Correction
Link to comment
Share on other sites

So you want something like this?

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

Global $aFileList = _FileListToArrayRec(@DesktopDir & "\test123", "*.pdf", _
    $FLTAR_FILES+$FLTAR_NOSYSTEM+$FLTAR_NOHIDDEN, _
    $FLTAR_RECUR, $FLTAR_FASTSORT, $FLTAR_FULLPATH)
If @error = 1 Then Exit

; Display Results
;~ _ArrayDisplay($aFileList, " Results")

Global $aRenamePDF
For $i = 1 To $aFileList[0]
    ; Get folder name
    $aRenamePDF = StringSplit($aFileList[$i],"\")
    ; Change pdf name to match folder name
    FileMove($aFileList[$i], @DesktopDir & "\Store PDF Files\" & $aRenamePDF[$aRenamePDF[0] - 1] & ".pdf", 8)
Next

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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