ฟอรั่ม PSsix

Would you like to react to this message? Create an account in a few clicks or log in to continue.

ฟอรั่มของบล็อก http://pssix.blogspot.com


3 posters

    การเปลี่ยนชื่อไฟล์

    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    การเปลี่ยนชื่อไฟล์ Empty การเปลี่ยนชื่อไฟล์

    ตั้งหัวข้อ by Monaliza 28/05/11, 09:36 am

    ขอถามหน่อยครับการเปลี่ยนชื่อไฟล์
    เช่น เปลี่ยนจาก test.txt เป็น test123.txt แบบนี้พอได้
    แต่การเปลี่ยนชื่อไฟล์พร้อมนามสกุล
    เช่น จาก test.exe เป็น test.txt
    test.txt เป็น view.jpg
    ต้องใช้คำสั่งไหนครับ
    em229

    newsak2005
    newsak2005
    ระงับสมาชิก
    ระงับสมาชิก


    การเปลี่ยนชื่อไฟล์ Empty
    จำนวนข้อความ : 115
    ความนิยม : 0
    เข้าร่วมเมื่อ : 08/05/2011

    การเปลี่ยนชื่อไฟล์ Empty Re: การเปลี่ยนชื่อไฟล์

    ตั้งหัวข้อ by newsak2005 28/05/11, 02:56 pm

    Code:

    #include <Process.au3>

    Global $sCommand = 'REN Monalisa.exe Monalisa.txt'  ;Add command and file to change name type.
    Local $btn = MsgBox(36, "", "Do you wanted file rename type?")
    If $btn = 7 Then Exit
    _RunDOS ($sCommand)
    If Not @error Then
       MsgBox(64, "", "File rename type successful.")
    Else
       MsgBox(48, "Error!", "Cannot change file name type.")
    EndIf
    OR
    Code:

    #include <Process.au3>

    Global $oFile = 'Monalisa.exe', $nFile = 'Monalisa.txt'  ;New file to change name type.
    Global $sCommand = 'REN Monalisa.exe Monalisa.txt'

    If Not FileExists($oFile)Then
        MsgBox(0, "", "Cannot found file " & $oFile)
        Exit
    EndIf

    Local $btn = MsgBox(36, "", "Do you wanted rename type " & $oFile &"?")
    If $btn = 7 Then Exit

    Dim $i
    ProgressOn("", "", "", 362, 230)
    For $i = 0 To 100 Step 5
       _RunDOS ($sCommand)
       If Not @error Then
           ProgressSet($i, "", "Convertting.." & $i & "%")
           Sleep(1)
       EndIf
    Next
    ProgressSet(100, "", "Convertting..100%")
    If FileExists($nFile)Then
       MsgBox(64, "", "File rename type successful.")
          ProgressOff()
    Else
       MsgBox(48, "Error!", "Cannot change file name type.")
    EndIf
    ---------------------------------------------------------------------
    เดี๋ยวสร้างโปรแกรมสำหรับเปลี่ยน ชื่อ - สกุล ไฟล์ต่างๆ มาให้ใช้
    POS
    POS
    PSsix
    PSsix


    การเปลี่ยนชื่อไฟล์ Empty การเปลี่ยนชื่อไฟล์ Empty การเปลี่ยนชื่อไฟล์ Empty
    จำนวนข้อความ : 1152
    ความนิยม : 326
    เข้าร่วมเมื่อ : 19/07/2010

    การเปลี่ยนชื่อไฟล์ Empty Re: การเปลี่ยนชื่อไฟล์

    ตั้งหัวข้อ by POS 28/05/11, 05:47 pm

    ใช้คำสั่ง FileMove

    Code:
    FileMove("C:\aaa.txt", "c:\bbb.bmp")
    newsak2005
    newsak2005
    ระงับสมาชิก
    ระงับสมาชิก


    การเปลี่ยนชื่อไฟล์ Empty
    จำนวนข้อความ : 115
    ความนิยม : 0
    เข้าร่วมเมื่อ : 08/05/2011

    การเปลี่ยนชื่อไฟล์ Empty Re: การเปลี่ยนชื่อไฟล์

    ตั้งหัวข้อ by newsak2005 28/05/11, 09:36 pm

    โค๊ดโปรแกรมใช้สำหรับ Rename

    Code:

    #NoTrayIcon
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Include <File.au3>
    #include <Process.au3>

    Opt("MustDeclareVars", 1)

    Global $guititle = 'File rename sample'
    Global $message1 = 'Choose'
    Global $message2 = 'file name? type?'
    Global $szDrive, $szDir, $szFName, $szExt

    Local $hWnd = GUICreate($guititle, 254, 155, -1, 303)
    Local $Input1 = GUICtrlCreateInput("", 16, 32, 137, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN))
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetState(-1, $GUI_FOCUS)
    GUICtrlCreateLabel("Old file name type", 40, 15, 100, 17)
    Local $Input2 = GUICtrlCreateInput("", 16, 85, 217, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_WANTRETURN))
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlCreateLabel("New file name type", 80, 68, 100, 17)
    Local $Button1 = GUICtrlCreateButton("Browse", 160, 30, 75, 25, $WS_GROUP)
    Local $Button2 = GUICtrlCreateButton("OK", 88, 120, 75, 25, $WS_GROUP)
    GUICtrlSetCursor(-1, 0)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW)

    While 1
       Local $nMsg = GUIGetMsg()
       Switch $nMsg
          Case $GUI_EVENT_CLOSE
             Exit
            Case $Button1
             Local $filetable = FileOpenDialog($message1, @DesktopDir & "\", "All file (*.*)", 1 + 4, "", $hWnd)
             Local $prog_path = _PathSplit($filetable, $szDrive, $szDir, $szFName, $szExt)
             If Not $filetable Then ContinueLoop
             GUICtrlSetData($Input1, $prog_path[3]&$prog_path[4])
             GUICtrlSetData($Input2, $message2)
             If GUICtrlRead($Input2) <> '' Then GUICtrlSetState($Button2, $GUI_ENABLE)
          Case $Button2
             If Not StringInStr(GUICtrlRead($Input2), '.') Then
                    MsgBox(48, "Error!", "Cannot rename.", 0, $hWnd)
                 ContinueLoop
             Else
                 _RunDOS("REN"&' '&$prog_path[3]&$prog_path[4]&' '& GUICtrlRead($Input2))
                 If Not @error And FileExists(GUICtrlRead($Input2))Then
                    Sleep(1500)
                   MsgBox(64, "", "Rename successful.", 0, $hWnd)
                Else
                   MsgBox(48, "Error!", "Cannot rename.", 0, $hWnd)
                   ContinueLoop
                EndIf
                    strreset()
             EndIf
       EndSwitch
    WEnd

    Func strreset()
       GUICtrlSetData($Input1, "")
       GUICtrlSetState($Input1, $GUI_FOCUS)
       GUICtrlSetData($Input2, "")
       GUICtrlSetState($Button2, $GUI_DISABLE)
    EndFunc
    Monaliza
    Monaliza
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Program Coder
    จำนวนข้อความ : 213
    ความนิยม : 7
    เข้าร่วมเมื่อ : 03/10/2010

    การเปลี่ยนชื่อไฟล์ Empty Re: การเปลี่ยนชื่อไฟล์

    ตั้งหัวข้อ by Monaliza 29/05/11, 09:52 am

    ขอบคุณทุกท่านที่ให้คำแนะนำนะครับ

      เวลาขณะนี้ 02/05/24, 06:47 am