Jump to content
GordonNT

Store a file content and write it to an other one

Recommended Posts

GordonNT

Hi,

I am trying to create a script that could read a file, store its content (in a txt file for example) and then write it to a new file ?

 

I tried this but it does not work, and strangely, the new file is bigger than the original :

 

#include <File.au3>

local $hFile = FileOpen( "C:\Users\Moi\Desktop\image.png" )
local $f = fileRead( $hFile )

_FileCreate( "C:\Users\XXX\Desktop\file\image.png" )
FileWrite("C:\Users\XXX\Desktop\file\image.png", $f)
FileClose($hFile)

 

 

Share this post


Link to post
Share on other sites
xcaliber13

I could be wrong but I do believe that FileOpen will not read a .png image file.

Share this post


Link to post
Share on other sites
GordonNT
6 minutes ago, xcaliber13 said:

I could be wrong but I do believe that FileOpen will not read a .png image file.

so, how am I supposed to do ? :sweating:

Share this post


Link to post
Share on other sites
JLogan3o13

If you are using .png why are you not simply copying the file from one place to another?


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
GordonNT
5 minutes ago, JLogan3o13 said:

If you are using .png why are you not simply copying the file from one place to another?

I would like to transfrom the file to string, so I can store this string in a file. Then I can use this string to recreate the file

 

Well, it's not really clear but I hope you can understand

Share this post


Link to post
Share on other sites
JLogan3o13

Nope, not a bit. What format, simple text or something else? What kind of file? To what end? Perhaps there is a better way? 

The more you provide the better able we are to assist: "I want to convert .png to text and then back" is a whole lot more difficult to assist with than "I want to convert an image to Base64 for use in program XYZ, then convert it back because abc".


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
GordonNT
2 minutes ago, JLogan3o13 said:

Nope, not a bit. What format, simple text or something else? What kind of file? To what end? Perhaps there is a better way? 

The more you provide the better able we are to assist: "I want to convert .png to text and then back" is a whole lot more difficult to assist with than "I want to convert an image to Base64 for use in program XYZ, then convert it back because abc".

What i want to do is :

 

I have a file (X) and I want to convert it to a txt one (Y)

 

The txt file will be stored on the desktop

 

We remove X

 

Later, we read Y and create X

Share this post


Link to post
Share on other sites
JLogan3o13

Again, my question is what does converting it to text gain you in the scope of your process? Why not move the file, then move it back, if it will not have changed?

There are plenty of threads on the forum about converting images to Base64 or some other means - try the forum search function and you will no doubt find some - although I am not aware of any for just converting to flat text. It seems wholly inefficient, hence the questions; I am willing to bet there is a better way to accomplish what you are after.


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
GordonNT
10 minutes ago, JLogan3o13 said:

Again, my question is what does converting it to text gain you in the scope of your process? Why not move the file, then move it back, if it will not have changed?

There are plenty of threads on the forum about converting images to Base64 or some other means - try the forum search function and you will no doubt find some - although I am not aware of any for just converting to flat text. It seems wholly inefficient, hence the questions; I am willing to bet there is a better way to accomplish what you are after.

I convert to image in order to net let the picture accessible

Let's say that my goal is to "hide" some pictures in a txt file

I have an other question, why is my txt file (Y) is bigger than the image (X) ?

Share this post


Link to post
Share on other sites
JLogan3o13

For your question: (txt != image) Not sure why you would expect two different ways of representing an object to be the exact same size.

For your goal, would not setting permissions on the file, setting it to hidden, or setting permissions on the folder in which it resides, be a much simpler and best practice way to accomplish your task? Any time you convert a file from one format to another and then back again you risk corruption; which requires that much more logic to accommodate those potential issues. If all you want to do is prevent/limit access, there are built-in tools for doing just that.


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
GordonNT
4 minutes ago, JLogan3o13 said:

For your question: (txt != image) Not sure why you would expect two different ways of representing an object to be the exact same size.

For your goal, would not setting permissions on the file, setting it to hidden, or setting permissions on the folder in which it resides, be a much simpler and best practice way to accomplish your task? Any time you convert a file from one format to another and then back again you risk corruption; which requires that much more logic to accommodate those potential issues. If all you want to do is prevent/limit access, there are built-in tools for doing just that.

Thanks for all

The issue with Windows permissions is that you always be able to get around them

Anyways, i'll just store those images to

@LocalAppDataDir

and it should be ok

Thanks again

Share this post


Link to post
Share on other sites
JLogan3o13

As I said, if you are dead set on converting, a quick search of the forum (or Google) will show you some threads where this has been done - although not as flat text. Good luck in your endeavors.

Also, as you post in the future, please don't quote whatever the person last said. Most of us remember what we said (we were there when we said it) and it needlessly pads the thread :)


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
careca

I did a similar thing but it was for video, and it grabs the first, say 700kb and moves them to the end of the file, and rename it without extension, so even if you give it an extension, it won't open because the file is all "messed up". If you want I can post something that is close enough to what you ask.


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
careca

Check this out:

Inconspicuous

The idea is to hide files, not full encryption so no good for sensitive data, but enough to most people not being able to figure out what the files are, more info on the page.


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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

×