Jump to content
Sign in to follow this  
cmlp13

Remove characters from a lot file

Recommended Posts

cmlp13

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

Share this post


Link to post
Share on other sites
monoceres

Welcome to the forums :)

Take a look at _FileListToToArray(), the string functions and FileMove() in the helpfile, they should provide everything you need :(

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Hiyoal

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 :)

Share this post


Link to post
Share on other sites
cmlp13

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.