Jump to content

Mass rename to uppercase


MHz
 Share

Recommended Posts

I have been working on my first autoit gui script. Cannot wait for final release, I guess. Titled - Windows XP Unattended CD SlipStream Plus.

My project is near end, but testing in virtual pc, I get a error of usbehci.sys not found. I have had this problem before. I am using Dircopy to get the files from the cd. Converting all files in I386 directory to uppercase seems to solve it. But how do I do this with autoit? Using Filemove will not work with a cd to rename to uppercase? Anyone please help.

Here is the working version to see.

Edited by MHz
Link to comment
Share on other sites

You are wanting to rename all of the files to upper case once you copy them to the HDD? I am not quite sure I understand your question.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Yes, I am wanting to rename the files to uppercase, so windows setup will see all the files. Some kind of setup glitch about lowercase?

I could use cdimage to change the case but because a $oem$ folder will be used, I do not want the files within it, changed to uppercase. Just the I386 files.

So I am looking for a function etc, that could give me the ability to change the case of the filenames.

Hope, I am alittle more clear.

Link to comment
Share on other sites

That will work this-is-me as I do not know of a current AutoIt function that anyone has written to do that.

Of course you could always write your own function MHz.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

;CHECK HERE CHECK HERE!
$sFolder = ' ';Folder to rename all files inside.
;CHECK HERE CHECK HERE!

if StringLeft($sFolder,1) <> '\' then $sFolder=$sFolder & '\'

$aFiles = _FileSearch($sFolder,5)
For $c = 1 to $aFiles[0]
   RunWait(@comspec & ' /c ren "' & $aFiles[$c] & '" "' & StringUpper( StringTrimLeft($aFiles[$c],StringInStr($aFiles[$c],'\',0,-1))) & '"','',@SW_HIDE)
   
Next



Exit
Func _FileSearch($sIstr, $iSF)
  ; $iSF can sum up.
  ; $iSF = 4 means don't return also folders, only files.
  ; $iSF = 2 means stop at the first found.
  ; $iSF = 1 means looking in subfolders.
   
  ; An array is returned with the full path of all files found. The pos [0] keeps the number of elements.
   Local $sIstr, $iSF, $sCriteria, $sBuffer, $iH, $iH2, $sCS, $sCF, $sCF2, $sCP, $sFP, $sOutPut = '', $aNull[1]
   $sCP = StringLeft($sIstr, StringInStr($sIstr, '\', 0, -1))
   If $sCP = '' Then $sCP = @WorkingDir & '\'
   $sCriteria = StringTrimLeft($sIstr, StringInStr($sIstr, '\', 0, -1))
   If $sCriteria = '' Then $sCriteria = '*.*'
   
  ;To begin we seek in the starting path.
   $sCS = FileFindFirstFile($sCP & $sCriteria)
   While $sCS <> - 1
      $sCF = FileFindNextFile($sCS)
      If @error Then
         FileClose($sCS)
         ExitLoop
      EndIf
      If $sCF = '.' Or $sCF = '..' Then ContinueLoop
      If Not (BitAND($iSF, 4) And StringInStr(FileGetAttrib($sCP & $sCF), 'd')) Then
         $sOutPut = $sOutPut & $sCP & $sCF & @LF
         If BitAND($iSF, 2) Then ExitLoop
      EndIf
   Wend
   
  ;And after, if needed, in the rest of the folders.
   If (BitAND($iSF, 2) Or BitAND($iSF, 3) And $sOutPut = '') Or (BitAND($iSF, 1) And Not BitAND($iSF, 2)) Then
      $sBuffer = @CR & $sCP & '*' & @LF;The buffer is set for keeping the given path plus a *.
      Do 
         $sCS = StringTrimLeft(StringLeft($sBuffer, StringInStr($sBuffer, @LF, 0, 1) - 1), 1);current search.
         $sCP = StringLeft($sCS, StringInStr($sCS, '\', 0, -1));Current search path.
         $iH = FileFindFirstFile($sCS)
         While $iH <> - 1
            $sCF = FileFindNextFile($iH)
            If @error Then
               FileClose($iH)
               ExitLoop
            EndIf
            If $sCF = '.' Or $sCF = '..' Then ContinueLoop
            If StringInStr(FileGetAttrib($sCP & $sCF), 'd') Then
               $sBuffer = @CR & $sCP & $sCF & '\*' & @LF & $sBuffer;Every folder found is added in the begin of buffer
               $sFP = $sCP & $sCF & '\';                            for future search
               $iH2 = FileFindFirstFile($sFP & $sCriteria);         and checked with the criteria.
               While $iH2 <> - 1
                  $sCF2 = FileFindNextFile($iH2)
                  If @error Then
                     FileClose($iH2)
                     ExitLoop
                  EndIf
                  If $sCF2 = '.' Or $sCF2 = '..' Then ContinueLoop
                  If Not (BitAND($iSF, 4) And StringInStr(FileGetAttrib($sFP & $sCF2), 'd')) Then
                     $sOutPut = $sOutPut & $sFP & $sCF2 & @LF;Found items are put in the Output.
                     If BitAND($iSF, 2) Then
                        FileClose($iH2)
                        FileClose($iH)
                        ExitLoop 3
                     EndIf
                  EndIf
               Wend
            EndIf
         Wend
         $sBuffer = StringReplace($sBuffer, @CR & $sCS & @LF, '')
      Until $sBuffer = ''
   EndIf
   
   If $sOutPut = '' Then
      $aNull[0] = 0
      Return $aNull
   Else
      Return StringSplit(StringTrimRight($sOutPut, 1), @LF)
   EndIf
EndFunc  ;==>_FileSearch

Link to comment
Share on other sites

@ezzetabi

Just had to do alittle change to you brilliant script. It was taking 3-4 minutes to process 5711 files. I changed it so it would write to a bat file first, wkich reduced it down to 3-4 seconds. As changes are shown.

;CHECK HERE CHECK HERE!
$sFolder = '';Folder to rename all files inside.
;CHECK HERE CHECK HERE!

If StringLeft($sFolder, 1) <> '\' Then $sFolder = $sFolder & '\'
$aFiles = _FileSearch($sFolder, 4)
$hnd = FileOpen('Conversion.bat', 1)
For $c = 1 To $aFiles[0]
   FileWrite($hnd, 'ren "' & $aFiles[$c] & '" "' & StringUpper( StringTrimLeft($aFiles[$c], StringInStr($aFiles[$c], '\', 0, -1))) & '"' & @CRLF)
Next
FileClose($hnd)
RunWait('Conversion.bat', '')
FileDelete('Conversion.bat')

This great script that you provided, deserves scripts and scraps imsertion. :)

Link to comment
Share on other sites

Of course starting a single Cmd session with all commands is much faster than one per one. I did not think that.

Maybe because I tested in much less files.

Glad you found a workaround!

Edit why did you changed _FileSearch($sFolder, 5) to _FileSearch($sFolder, 4)? No need for subdirs?

Edited by ezzetabi
Link to comment
Share on other sites

You have good vision. I guess that was from the sample that I tested with alterations. Glad you saw this, saves displaying bad info. But my script does have 5 instead of 4, as displayed.

$sFolder = $open & '\i386';Folder to rename all files inside.
      If StringLeft($sFolder, 1) <> '\' Then $sFolder = $sFolder & '\'
      $message = GUICtrlCreateLabel('Converting I386 files to Uppercase', 10, 405, 570, 20)
      $aFiles = _FileSearch($sFolder, 5)
      $hnd = FileOpen(@TempDir & '\WXPUCDP_Temp.bat', 1)
      For $c = 1 To $aFiles[0]
       FileWrite($hnd, 'ren "' & $aFiles[$c] & '" "' & StringUpper( StringTrimLeft($aFiles[$c], StringInStr($aFiles[$c], '\', 0, -1))) & '"' & @CRLF)
      Next
      FileClose($hnd)
      RunWait(@TempDir & '\WXPUCDP_Temp.bat', '', @SW_HIDE)
      FileDelete(@TempDir & '\WXPUCDP_Temp.bat')

It works great, thanks. ezzetabi. :)

Link to comment
Share on other sites

Guest Py7|-|[]/\/

Since in the past few days after I made the 1337 translator everyone is going StringReplace() crazy, you might as well just do a stringreplace function and save time. Just replace all available lowercase letters with a Capital letter.

$text = InputBox("Welcome", "Please enter what u wanna make capital.")

$change = StringReplace($text, "a", "A", 0, 1)

etc...

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