Jump to content

Please help me in Renaming a file and extension


mohan93
 Share

Go to solution Solved by trancexx,

Recommended Posts

Hi Everyone, 

I have 2 queries, please assist,

1. Rename a file:

I have a file in C:TempGLW123.tmp 

I need to rename the file to Setup.wse  and the file should be placed in the same directory C:temp

2. Embedding a .VBS file within the autoScript complied EXE.

i can achieve the above renaming functionality  using below VBS. 

SearchFileName = "GLW123.tmp"               
RenameFileTo   = "SETUP.WSE"
For each file In folder1.Files    
    'WScript.Echo (file.Name)
    If instr(file.name, searchFileName) = 1 Then
         file.name = renameFileTo
           Exit For
    End If
Next
 
is there any option to embed this VBS inside the EXE and use the VBS in my autoit script.
 
Please Help.
 
Link to comment
Share on other sites

  • Moderators

Hi, mohan93. Why bother using the vbs at all? Check the help file for more info on _FileListToArray.

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

Local $aArray = _FileListToArray("C:\Temp", "*", 1)

    For $i = 1 To $aArray[0]
        If $aArray[$i] = "GLW123.tmp" Then FileMove("C:\Temp\GLW123.tmp", "C:\Temp\SETUP.WSE", 1)
    Next
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Solution

 

Hi, mohan93. Why bother using the vbs at all? Check the help file for more info on _FileListToArray.

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

Local $aArray = _FileListToArray("C:\Temp", "*", 1)

    For $i = 1 To $aArray[0]
        If $aArray[$i] = "GLW123.tmp" Then FileMove("C:\Temp\GLW123.tmp", "C:\Temp\SETUP.WSE", 1)
    Next

Uhm, why are you using _FileListToArray() at all? That doesn't make much sense to me.

Just FileMove() it.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • Moderators

Trancexx, I only did so because the OP showed that he was doing a search in the vbs in his OP. It appeared he was searching the directory to see if the file exists, and then moving. Otherwise you are of course correct, I would have simply done a FileMove.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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...