Need help with file manipulation

Started by Gregjazz, Mon 08/08/2005 07:38:09

Previous topic - Next topic

Gregjazz

Basically I need a way to rename a file from AGS. I have the AGS File Plugin, and that has a "FileRename" function, but in its parameters, two "chars" are needed, not strings. So I can't figure out how to get that working.

I'm sure it wouldn't be too difficult or take too long to make a plugin that could rename files... if I can't get this working, would someone be willing to make me that plugin really fast? I would do it myself if I had C++, but I don't. :(

Gilbert

Hmmm I just downloaded the plugin and read its document:
QuoteFileRename (string oldname, string newname);
Maybe you're using some other version of the plugin?

ALso, maybe it's some issue with the new String handling system in V2.71 beta.

Gregjazz

Quote from: Gilbot V7000a on Mon 08/08/2005 08:03:12
Hmmm I just downloaded the plugin and read its document:
QuoteFileRename (string oldname, string newname);
Maybe you're using some other version of the plugin?

ALso, maybe it's some issue with the new String handling system in V2.71 beta.

I think you're probably right that it's an older version -- seeing that the one I have doesn't have any documentation. Where can you download it? (I'll look for it, too)

Gilbert


Rui 'Trovatore' Pires

Heh. Today is the day of revelations. I not only found that my page is indeed a useful place, I also found I'm still refered to as "redruM". Joy.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Gregjazz

Ah yes indeed it is a newer version!

Gilbert

Quote from: Rui "Brisby" Pires on Mon 08/08/2005 08:08:16
Heh. Today is the day of revelations. I not only found that my page is indeed a useful place, I also found I'm still refered to as "redruM". Joy.

Hehe, because i can never spell your new nick.

Rui 'Trovatore' Pires

Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Gregjazz

And... I have that same 'char' problem. Looks like the newer version of AGS is incompatible. :(

And this is AGS 2.7, so it doesn't have those new string things...

Gilbert

I tried it, it doesn't work with V2.62 either.
Since I'm a natural plugin hater, I won't be that adventurous to invest on it further.

A less elegant method is to copy the file to another new file  byte by byte, you can reuse the old file by overwriting it, that doesn't even need a plugin.

Gregjazz

Quote from: Gilbot V7000a on Mon 08/08/2005 09:29:53
I tried it, it doesn't work with V2.62 either.
Since I'm a natural plugin hater, I won't be that adventurous to invest on it further.

A less elegant method is to copy the file to another new file  byte by byte, you can reuse the old file by overwriting it, that doesn't even need a plugin.

I thought about that, but was reluctant to try. I guess that's my only option since I hope to finish this little project in the next few days and needed something immediate.

I'll give it a shot. Hopefully CJ will implement a FileRename function (file.rename or whatever) and maybe a FileDelete, etc.

Gilbert

Quote from: Geoffkhan on Mon 08/08/2005 09:36:04
I thought about that, but was reluctant to try. I guess that's my only option since I hope to finish this little project in the next few days and needed something immediate.

Something like below (untested), but it's obviously not efficient, since it's not smart to do a file copy when you just need a file rename anyway:
function FileCopy(string inname, string outname) {
Ã,  File* infile=File.Open(inname, eFileRead);
Ã,  if (infile==null) return 1; //error opening file for reading.
Ã,  File* outfile=File.Open(outname, eFileWrite);
Ã,  if (infile==null) {
Ã,  Ã,  infile.Close();
Ã,  Ã,  return 1; //error opening file for writing.
Ã,  }
Ã,  while (!infile.EOF) outfile.WriteRawChar(infile.ReadRawChar());
Ã,  infile.Close();
Ã,  outfile.Close();
}


Of course, if your file is a bit "large" the function will crash, due to the while loop iteration limit. There're workarounds, but in my opinion it's probably not worth the effort for such a simple task.

Gregjazz

Quote from: Gilbot V7000a on Mon 08/08/2005 11:24:31
Quote from: Geoffkhan on Mon 08/08/2005 09:36:04
I thought about that, but was reluctant to try. I guess that's my only option since I hope to finish this little project in the next few days and needed something immediate.

Something like below (untested), but it's obviously not efficient, since it's not smart to do a file copy when you just need a file rename anyway:
function FileCopy(string inname, string outname) {
  File* infile=File.Open(inname, eFileRead);
  if (infile==null) return 1; //error opening file for reading.
  File* outfile=File.Open(outname, eFileWrite);
  if (infile==null) {
    infile.Close();
    return 1; //error opening file for writing.
  }
  while (!infile.EOF) outfile.WriteRawChar(infile.ReadRawChar());
  infile.Close();
  outfile.Close();
}


Of course, if your file is a bit "large" the function will crash, due to the while loop iteration limit. There're workarounds, but in my opinion it's probably not worth the effort for such a simple task.

Yeah, the files I'm working with will tend to be over a meg in size. I don't want it to take ages to copy.

Hmmm... it'd be great if I could run a .bat file from AGS... I think I can run an .exe from AGS, so I'll think about that.

I just really need the ability to rename a file... if anyone comes up with a plugin doing that I'd be more than happy to Paypal some money...

Gregjazz

Okay, I got it working via use of a .bat file. Cool!

Pumaman

Would anyone else find a FileRename/FileDelete function useful? I think we've discussed it before and decided against it because of the potential to mess around with the player's system.

But functions restricted to the game folder only might do the trick, if they'd be useful?

Gregjazz

Really I would only need those functions to work in the game folder.

RickJ

I would find them very useful as well.     

Dorcan

Yes, definately, for the game folder AND its subfolders. In fact, it would be quite useful to have all the file functions working in subfolders as well (I'm thinking about the eFileWrite mode I would have used in this case, but had to create a plugin which allowed me to create/move a file into the "/profile" folder)

Gregjazz

Quote from: Dorcan on Tue 09/08/2005 23:48:11
Yes, definately, for the game folder AND its subfolders. In fact, it would be quite useful to have all the file functions working in subfolders as well (I'm thinking about the eFileWrite mode I would have used in this case, but had to create a plugin which allowed me to create/move a file into the "/profile" folder)

Yeah, support for files in subfolders would be great too.

GarageGothic

Yes, I've been wishing for these functions for a while now (I thought the file plugin might do the trick, but I'd rather do without plugins). Remember CJ, if you wanted to mess up the player's files, you could just RawWrite to them to corrupt them anyway, so as long as it's restricted to the game directory and subdirectories, there should be no problem.

SMF spam blocked by CleanTalk