Jump to content

Recommended Posts

Posted

Hello.

Could you help me please with the next problem regarding batch programming?

I want to move a file to one or two variable name directories. The parent directory of the variable name directory is a fix name but the "child" names directories are variable. I want to distribute this file to those 2 directories without knowing their name. The only fixed directory which name will be always the same is the parent one.

Ex:

C:\backup\variable name directory 1

C:\backup\variable name directory 2

is this possible?

Thanks


Posted

Is it possible? Yes. But you'll need to give more complete examples. You say "move a file to one or two variable name directories" Meaning move the file to one or the other, or move to either one or both? How will you decide which directory you're moving the file to? is it based in the file name? How? How are the variable name directories named? Based on what?

Cheers and Regards

Posted (edited)

Hello again.

I want to make a batch script that will backup some information and I will integrate this script in a boot cd like hiren's. The purpose is to boot the cd if the os is not working anymore and with one click to back-up my personal information. I don't want to browse folders and extract those files one by one. By reversing it's actions I will make a second script that will deploy my files in the right folders after os reinstall. I don't want to a make an os image since I could use that image on a similar pc and I don't want my info go there.

About the script:

- I managed to make it back-up my ppoe info file, but on a clean install even if I'm deploying the needed file in it's place it's not working. I don't know if the script should make some registry entries as well. Ex: the user and pass are stored in a .pbk file. If I back-up it and after os reinstall I copy it where it should be the ppoe connection is not starting. I presume it's something more to be done, maybe in the registry. So it's not working for the moment and it's useless. I will remake the connection manually.

- I managed to make it back-up some fix name folders from desktop that will always be there. Ex: pics, notes. And a download folder which has also a fixed name and path.

- I managed to back-up from firefox the entire PROFILES folder, but I need to back-up just 3 files (1 with the password and 2 for the bookmarks) from each of the 2 profiles folders that I'm having. One profile contains bookmarks and passwords and the other just bookmarks which are the same for each profile.The only problem is that the profile names are variable: XXXXXXXX.default.

So, I need a script that will access the %AppData%\Mozilla\Firefox\Profiles\ path and without knowing from the start what are the profiles names to go inside them and back up from each, 3 files and save them separately. Of course from the second profile 1 file (with password) will be missing.

After reversing, the script will deploy those 3 files in every of the 2 existing profiles without knowing from the start the name of the profiles. From the second profile I will delete manually the password file.

Even if I have to do some manually operation after os reinstall the main purpose of the script is to back-up my files with one click.

So, it's possible?

Thanks.

Edited by noriel
Posted

Please do not shout. It will not get you help any faster, it will just p*** everybody off annoy everyone.

Are we able to help you? Yes. Will we? Hmmmm We would much rather help you learn how to do this yourself than do it for you.

I have no idea at all how capable or experienced you are, but you finally seemed to describe what it was you wanted to do. It seemed to me that you just didn't know how to handle the unknown, variable folder name situation. To help you learn how to handle that, try creating a simple test.cmd file with the following code in it:

@ECHO OFF & SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /F "tokens=*" %%G IN ('dir /B /AD "%AppData%\Mozilla\Firefox\Profiles"') DO (
ECHO %%G
)

Open a Command Window and run test.cmd. You should notice that %%G will have the value of whatever the unknown folder name(s) is/are. Within the FOR loop you can do whatever you like with that name such as assign it to another variable to use later, etc. Does that help?

Two reference sites I would suggest to help you learn all the ins and outs of batch scripting are:

http://ss64.com/nt/

http://www.robvanderwoude.com/batchfiles.php

Try some things yourself and let us know how it goes. Post the code you tried and the results you got and ask us questions regarding what you don't understand.

Cheers and Regards

Posted (edited)

I wasn't shouting. Caps lock remained active from another application. I'm sorry you understood that I am shouting.

Regarding my knowledge level: it's low. I want to learn. I am trying to learn batch programming for 2-3 days and I thought it would be a good idea to learn it doing useful things instead of learning lots of theoretical stuff and forget them before using them. For example trying to do a useful thing I learned about dir and enable. If I was going just on learning after a month I probably wasn't able to write that code and were good chances to forget some thing until then since I wasn't trying them in the practical way.

When I read that code you wrote I didn't understood a thing of it. I read and now I have an idea about what it is doing.

I found what are those 2 enable commands, the dir command attributes and the command syntax.

I want to learn and thanks that you tried to help me using that chinese saying about the fisherman and the fishing line.

But since I am not having any programming knowledge and my brain isn't working like a programmer's one I don't understand in what direction I should go. I mean I don't know if I should find a way to run a command using that variable or extract that name from the loop and use it in the copy command.

I don't want the code for it.

If you are willing please give me more indications about the direction I should study.

Thanks a lot for helping me.

ps: If you consider that your indications were very clear and I am too dumb to learn something I will stop about learning any programming. I don't intend to waste others time and good intentions.

Edited by noriel
Posted

Like most tasks, especially when learning something new, it's usually best to break the task down into smaller pieces. I would think the first step is to decide you need to end up with two scripts - one to back up the files and one to restore them. The second thing to remember, especially at first, is to use ECHO a lot, substituting it for other commands so you can see what would happen if you used the real command instead of ECHO.

I would suggest just trying to figure out how to copy the Firefox profile files somewhere else - say for example into a folder located next to where your test.cmd is located named the same as the unknown folders in the profile. Create an empty folder at the root of C: - C:\test. As before, create a file test.cmd in that folder with the following code: (Change file1.txt - file3.txt to be the names of the three files from the profile that you said you wanted to save.)

@ECHO OFF & SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
(SET FFProfile="%AppData%\Mozilla\Firefox\Profiles")
FOR /F "tokens=*" %%G IN ('dir /B /AD %FFProfile%') DO (
ECHO MD %%G
ECHO copy %FFProfile%\%%G\file1.txt %%G
ECHO copy %FFProfile%\%%G\file2.txt %%G
ECHO copy %FFProfile%\%%G\file3.txt %%G
)

Open a command window and run that code and see what happens. It will just echo to the command window the exact commands that would be used if ECHO wasn't being used. Then delete "ECHO" from the four lines inside the FOR loop, leaving:

@ECHO OFF & SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
(SET FFProfile="%AppData%\Mozilla\Firefox\Profiles")
FOR /F "tokens=*" %%G IN ('dir /B /AD %FFProfile%') DO (
MD %%G
copy %FFProfile%\%%G\file1.txt %%G
copy %FFProfile%\%%G\file2.txt %%G
copy %FFProfile%\%%G\file3.txt %%G
)

Run this code and the folder(s) will be created inside the test folder and the three files you were looking for will be copied there from the Firefox profile.

Read the reference sites as necessary and practice with this simple example until you understand what it is doing. Build on this code to include another piece of what you want to do. Keep building until you have the whole task accomplished.

Now it's your turn. Either tell me how wonderful a teacher I am and that you understand it completely and you don't need my help any more, or post code that you have written explaining what you wanted it to do and what it is actually doing instead and what you don't understand. Either I or one of the other guys who like to play with batch will try to edit your code and help you learn - IF you do YOUR part.

Cheers and Regards

Posted (edited)

I am sorry if I upset you with something. Yes, you are a wonderful teacher :), but I will come here for help when I will have something (my code) to discuss about. And I am really eager to learn more. For example I didn't understood from the beginning that FOR F/ command.and all the other stuff like delims and I begun to study. So at some point I managed to write by my own a batch file that is parsing words from a text file and echos the rest of the text to another file. I know this is child's play for you, but your directions helped me to understand much more than I knew yesterday. Now I know a little bit more like understanding more commands.

Now that you helped me more I will try to see how I'm doing myself and if needed come here to ask for help with a some code.

Thanks a lot!

Edited by noriel
Posted

No problem and you are quite welcome. Don't worry, you did not upset me at all. I'm glad you were able to understand my examples. The approach you plan sounds good. Good luck to you and please keep us informed of your progress. Who knows? The code you post here might help someone else. Feel free to ask questions if you get stuck.

Cheers and Regards

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...