Jump to content

Recommended Posts

Posted (edited)

hi im stuck with this I want to transfer the correct file in the existing folder

#include <File.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
$Read = "C:\New folder (3)"

$FLFiles1 = _FileListToArrayRec($Read, "*.xlsx", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_NOPATH)
_ArrayDisplay($FLFiles1)
For $i = 0 To UBound($FLFiles1) - 1
    $STR = StringTrimRight($FLFiles1[$i], 5)
    ConsoleWrite($STR & @CRLF)
    $dirS = DirGetSize($Read & "\" & $STR)
    If $dirS = -1 Then
        MsgBox(16, $STR, $dirS)
    Else
        FileMove($Read, $Read & "\" & $STR & "\" & $STR & ".xlsx")
    EndIf
next

I have 3 folders under "C:\New folder (3)" and I have 5 excel files:

folders:

C:\New folder (3)\1

C:\New folder (3)\3

C:\New folder (3)\5

excel files:

1.xlsx (value of column A are all 1)

2.xlsx (value of column A are all 2)

3.xlsx (value of column A are all 3)

4.xlsx (value of column A are all 4)

5.xlsx (value of column A are all 5)

 

 I run the above script and those excel file 1, 3, 5 was transfered in the 1, 3, and 5 folders but the value of transfered file in Column A are  different and file no. 4 and 5 still remains in the folder "C:\New folder (3)".... ???

whats wrong with the script???

 

 

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Posted

You would have to create the folder for 4 and 5 so you would need to change the last parameter of FileMove to 

8 - Create Folder
Or
9 - Create Folder and/or OverWrite

Posted (edited)

hi Subz,

I dont want to create the folder for 4 and 5, all i want is to transfer the excel file with existing folder.

I want to filemove these excel file:

1.xlsx (with value a of 1 in column A) filemove to folder 1

3.xlsx (with value a of 3 in column A) filemove to folder 3

5.xlsx (with value a of 5 in column A) filemove to folder 5

 

if i ran the script file 1, 3, and 5 are trasferred but if you open the transferred excel file the value of column A is different which means the file that was transfered was different and was renamed.

Im really stuck with this I dont know whats wrong with the script.

:sweating::sweating::sweating:

 

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Posted

Yeah that confused me 1.xlsx (with value a of 1 in column A) , do you mean within the .xlsx file Column A1 = 1, which Column are you referring too, I didn't think it was the .xlsx file since you never open the file, can you explain further?

Posted (edited)

I attached the example. in my side path is under "C:\New folder (3)"

sample.zip

use the above script and change the path you want. :sweating:

open the file after transferred.

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Posted

I'm still not sure what you want to happen to 2.xlsx and 4.xlsx but here is the script updated:

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

Local $sFileName, $iDirSize, $sFilePath= "C:\New folder (3)"
Local $aFileList = _FileListToArrayRec($sFilePath, "*.xlsx", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_NOPATH)
_ArrayDisplay($aFileList)
For $i = 1 To $aFileList[0]
    $sFileName = _WinAPI_PathRemoveExtension($aFileList[$i])
    If FileExists($sFilePath & "\" & $sFileName) = 0 Then
        MsgBox(4096, "Error", $sFilePath & "\" & $sFileName & " folder does not exist.", 5)
        ContinueLoop
    EndIf
    $iDirSize = DirGetSize($sFilePath& "\" & $sFileName)
    If $iDirSize = -1 Then
        MsgBox(16,$sFileName, $sFilePath & "\" & $sFileName & " is empty.", 5)
    Else
        FileMove($sFilePath & "\" & $aFileList[$i], $sFilePath & "\" & $sFileName & "\" & $aFileList[$i])
    EndIf
next

 

Posted (edited)

my goal is to transfer the excel file on the existing folder using the script on my first post..

file 1 which contains a text "file 1" should be transferred to folder no 1

file 3 which contains a text "file 3" should be transferred to folder no 3

file 5 which contains a text "file 5" should be transferred to folder no 5

file 2 which contains a text "file 2" should remain on the same folder C:\New folder (3)

file 4 which contains a text "file 5" should remain on the same folder C:\New folder (3)

I dont want to create folder for file 2 and 4 so they should remain on the same folder C:\New folder (3)

 

see attached pictures pictures:

 

 

1st step.jpg

2nd step.jpg

Edited by 232showtime
i got thousands of file that has an existing folder and i have thousands of files that doesnt have a folder. and i dont want to create folder for the other files because i want to check which one has a folder and which one doesnt have....

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Posted (edited)

your script is working perfectly, but please can you tell me whats the problem with the script on my first post???

by the way nice line here

$sFileName = _WinAPI_PathRemoveExtension($aFileList[$i])

new to me :sweating:

thanks @Subz

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Posted
  1. Line 8: The array should be starting at 1 not 0
  2. Line 11: You have a condition that says that if the folder size equals -1, why?  Why not just use FileExists function
  3. Line 17: Moving the folder "C:\New folder (3)" to "C:\New Folder (3)\x\x.xlsx (where x equals $sFolderName), so basically it was just moving the first file it found into that particular folder, you never specified the filename.

You can see the results of your script here: (I've changed the variables so that they're readable, but the code is the same, although of just used ConsoleWrite to show your syntax.

#include <File.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
$sSourceFolder = "C:\New folder (3)"

$aFileList = _FileListToArrayRec($sSourceFolder, "*.xlsx", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_NOPATH)
_ArrayDisplay($aFileList)
For $i = 0 To UBound($aFileList) - 1
    ConsoleWrite("Passthrough# := " & $i & @CRLF)
    $sFolderName = StringTrimRight($aFileList[$i], 5)
    ConsoleWrite("$sFolderName := " & $sFolderName & @CRLF)
    $iDirSize = DirGetSize($sSourceFolder & "\" & $sFolderName)
    ConsoleWrite($sFolderName & " - DirSize :=" & $iDirSize & @CRLF)
    If $iDirSize = -1 Then
        ConsoleWrite($sFolderName & " - DirSize :=" & $iDirSize & @CRLF)
    Else
        ConsoleWrite('FileMove("' & $sSourceFolder & ", " & $sSourceFolder & "\" & $sFolderName & "\" & $sFolderName & ".xlsx" & '")' & @CRLF)
    EndIf
next

 

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
×
×
  • Create New...