cmlp13 Posted May 20, 2008 Posted May 20, 2008 Is there an auto script that could remove the first four characters from a lot of files? I have 165 files, I need to remove the first four characters which are A number, an number, a period, and a space. For example: 01. File.ext Can anyone help
monoceres Posted May 20, 2008 Posted May 20, 2008 (edited) Welcome to the forums Take a look at _FileListToToArray(), the string functions and FileMove() in the helpfile, they should provide everything you need Edited May 20, 2008 by monoceres Broken link? PM me and I'll send you the file!
Hiyoal Posted May 20, 2008 Posted May 20, 2008 StringTrimLeft(). What you would basically do is do this: $file="C:\charfile.txt" $handle=FileOpen($file,0) ;read only $readhandle=FileRead($handle) ;reads the whole text file $newstring=StringTrimLeft($readhandle,4) ;removes the first 4 characters FileWrite("C:\charfileappended.txt",$newstring) FileClose($handle) Hiyoal
monoceres Posted May 20, 2008 Posted May 20, 2008 (edited) No, more like: #include <File.au3> $files = _FileListToArray(@ScriptDir) For $i = 1 To UBound($files) - 1 FileMove(@ScriptDir & "\" & $files[$i], @ScriptDir & "\" & StringTrimLeft($files[$i], 4)) Next Ooops, now I actually did the script for him Edited May 20, 2008 by monoceres Broken link? PM me and I'll send you the file!
cmlp13 Posted May 20, 2008 Author Posted May 20, 2008 No, more like: #include <File.au3> $files = _FileListToArray(@ScriptDir) For $i = 1 To UBound($files) - 1 FileMove(@ScriptDir & "\" & $files[$i], @ScriptDir & "\" & StringTrimLeft($files[$i], 4)) Next Ooops, now I actually did the script for him Thanks, worked perfectly! Originally, I had tried to make the file only include the characters I had wanted, but that took out the file extension and left the spaces: #include<file.au3> Dim $sourceFolder = @ScriptDir $Array = _FileListToArray($sourceFolder, "*.*", 1) For $i=1 To $Array[0] $result = StringRegExpReplace($Array[$i], "[^a-zA-Z\ \-_]", " ") FileMove($sourceFolder & "\" & $Array[$i], $sourceFolder & "\" & $result) Next
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now