Sign in to follow this  
Followers 0
Willow

If FileExists and DirMove code help

7 posts in this topic

I am attempting to rename an existing folder based on ticket ref# and date/time stamp. Although the code does run, it will not create the c:\tickets\TKT # mm-dd-yy-hh-mm folder.

Any help would be appreciated.

Do
$mkfld = InputBox("Create Ticket Backup Folder", "Enter Ticket Number ONLY", "", " M5", 250, 130)
If @error Then Exit
Until StringIsdigit($mkfld)
If FileExists($mkfld) Then DirMove($mkfld), ($mkfld) & @MON & "-" & @MDAY & "-" & @YEAR & "-" & @HOUR & "-" & @MIN)
DirCreate("c:\tickets\TKT # "&$mkfld)
If NOT @Error Then
  If DirCreate( $mkfld  ) Then
  MsgBox(0, "Success", "Ticket Backup Folder REF # " & $mkfld & " was created")
EndIf
EndIf

Share this post


Link to post
Share on other sites



Your DirMove statement is wrong. try something like:

Do
    $mkfld = InputBox("Create Ticket Backup Folder", "Enter Ticket Number ONLY", "", " M5", 250, 130)
    If @error Then Exit
Until StringIsDigit($mkfld)
If FileExists($mkfld) Then
    DirMove($mkfld, $mkfld & " " & @MON & "-" & @MDAY & "-" & @YEAR & "-" & @HOUR & "-" & @MIN)
    If @error Then
        MsgBox(0, "Error", "Error creating Ticket Backup Folder REF # " & $mkfld & "! Error returned is: " & @error)
        Exit
    EndIf
EndIf
DirCreate("c:\tickets\TKT # " & $mkfld)
If Not @error Then
    If DirCreate($mkfld) Then
        MsgBox(0, "Success", "Ticket Backup Folder REF # " & $mkfld & " was created")
    EndIf
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Willow,

$mkfld will be a string of digits. You are then testing for a filename equal to this string, does such a file exist?

If the file exists you are assumming that a dir of the same name exists. Is this true?

You also need to review the syntax for dirmove...

Can you explain in psuedo-logic what you are trying to do with the series of dircreate's?

kylomas

Edit: Never mind - too late, water got in b4 me

Edited by 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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@Water:

Thanks for the assist. I made a few changes to your code. However I am still having a somewhat related problem. The good news is that the code is now creating the correct folder ie: c:ticketsTKT # 22222.

Once the script is run a second time, it sees the existing folder and will create a backup folder such as "c:ticketsTKT # 22222 11-09-2011-19-42" folder which is correct.

What is strange though, when run either the first or second time, it is also creating a folder named 22222 in the saved scripts folder.

For example, save the attached code sample as ticket.au3 in a "c:myscripts" folder.

Next run it and it will create both a "C:ticketsTKT # 22222" folder (correct) and a "c:myscripts22222" folder." This is the underlying problem, why is it creating the "c:myscripts22222" folder" every time?

Do
    $mkfld = InputBox("Create Ticket Backup Folder", "Enter Ticket Number", "", " M5", 250, 130)
    If @error Then Exit
Until StringIsDigit($mkfld)
If FileExists($mkfld) Then
    DirMove( "c:ticketsTKT # " & $mkfld, "c:ticketsTKT # " &$mkfld& @MON & "-" & @MDAY & "-" & @YEAR & "-" & @HOUR & "-" & @MIN)
    If @error Then
        MsgBox(0, "Error", "Error creating Ticket Backup Folder TKT # " & $mkfld & "! Error returned is: " & @error)
        Exit
    EndIf
EndIf
DirCreate("c:ticketsTKT # " & $mkfld)
If Not @error Then
    If DirCreate($mkfld) Then
        MsgBox(0, "Success", "Ticket Backup Folder TKT # " & $mkfld & " was created")
    EndIf
EndIf
Edited by Willow

Share this post


Link to post
Share on other sites

If DirCreate($mkfld) Then
        MsgBox(0, "Success", "Ticket Backup Folder TKT # " & $mkfld & " was created")
    EndI

The DirCreate creates a new folder even in an if statement... thus its like saying, create a directory, if the directory is created successfully msgbox....

You want to replace that with

If Not @error Then
    If FileExists("c:ticketsTKT # " & $mkfld) Then
        MsgBox(0, "Success", "Ticket Backup Folder TKT # " & $mkfld & " was created")
    EndIf
EndIf

Share this post


Link to post
Share on other sites

The DirCreate creates a new folder even in an if statement... thus its like saying, create a directory, if the directory is created successfully msgbox....

Thanks, however that does not fix the problem of the script creating a "c:myscripts22222" folder.

From my previous post.

For example, save the attached code sample as ticket.au3 in a "c:myscripts" folder.

Next run it and it will create both a "C:ticketsTKT # 22222" folder (correct) and a "c:myscripts22222" folder." This is the underlying problem, why is it creating the "c:myscripts22222" folder" every time?

Share this post


Link to post
Share on other sites

Do
    $mkfld = InputBox("Create Ticket Backup Folder", "Enter Ticket Number", "", " M5", 250, 130)
    If @error Then Exit
Until StringIsDigit($mkfld)
If FileExists($mkfld) Then
    DirMove( "c:ticketsTKT # " & $mkfld, "c:ticketsTKT # " &$mkfld& @MON & "-" & @MDAY & "-" & @YEAR & "-" & @HOUR & "-" & @MIN)
    If @error Then
        MsgBox(0, "Error", "Error creating Ticket Backup Folder TKT # " & $mkfld & "! Error returned is: " & @error)
        Exit
    EndIf
EndIf
DirCreate("c:ticketsTKT # " & $mkfld)
If Not @error Then
    If FileExists("c:ticketsTKT # " & $mkfld) Then
        MsgBox(0, "Success", "Ticket Backup Folder TKT # " & $mkfld & " was created")
    EndIf
EndIf

This works fine for me

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  
Followers 0