Jump to content
Sign in to follow this  
quicksilver

Sort Files and move them into separate folders

Recommended Posts

quicksilver

Hi i Have files like this names:

LP2001060000N_00N.txt

LP2001060000N_00N.pdf

LP2001060000N_00N.idx

LP2001060000N_00N.rdy

in the folder are over 20.000 files and i want to move all the files with the same Year and Month (LP2001060000N_00N.rdy) in separate folders like 2001_06.

I want that the script create these folders and move all the files into the specified folder .

Can Anyone Help me with this problem?

Share this post


Link to post
Share on other sites
SmOke_N

Errr... what do you have so far?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
quicksilver

At the moment nothing.. because i dont know how to scan all the files and extract the year and month and create a folder :P

Share this post


Link to post
Share on other sites
SmOke_N

Do all the files start with LP?

Do all the files after the month have 0000?

Can you post absolute filename examples that you would be dealing with...?

Edit:

How far back do the files go?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
quicksilver

Start Charakters are LP, MW or RG

Yes 4 Zero's after the date. The Filename Examples are absolute.

Share this post


Link to post
Share on other sites
SmOke_N

Start Charakters are LP, MW or RG

Yes 4 Zero's after the date. The Filename Examples are absolute.

If StringInStr($FileName, 'LP') Then
    If Not StringInStr($NewFolder, _StringBetween($FileName, 'LP', '0000')) Then
        $NewFolder = $NewFolder & _StringBetween($FileName, 'LP', '0000') & Chr(01)
    EndIf
ElseIf StringInStr($FileName, 'MW') Then
    If Not StringInStr($NewFolder, _StringBetween($FileName, 'MW', '0000')) Then
        $NewFolder = $NewFolder & _StringBetween($FileName, 'MW', '0000') & Chr(01)
    EndIf
ElseIf StringInStr($FileName, 'RG') Then
    If Not StringInStr($NewFolder, _StringBetween($FileName, 'RG', '0000')) Then
        $NewFolder = $NewFolder & _StringBetween($FileName, 'RG', '0000') & Chr(01)
    EndIf
EndFunc

Func _StringBetween($s_String, $s_Start, $s_End = 0)
    $s_Start = StringInStr($s_String, $s_Start)+StringLen($s_Start)
    return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End)-$s_Start)
EndFunc

At the end of your search, or where ever you'll notice that the folder names are seperated by Chr(01), you can use this as the delimeter to create an array and make a folder either after your search is finished, or during the search if you are moving the files at the same time.

Edit:

Sometimes coding when your tired... you do things ass Backwards :lmao:... fixed a StringInStr() issue!!

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
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
Sign in to follow this  

×