Can I access a variable name directory without knowing it's name?
Posted 01 May 2012 - 03:54 PM
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.
C:\backup\variable name directory 1
C:\backup\variable name directory 2
is this possible?
Posted 01 May 2012 - 09:48 PM
Cheers and Regards
Posted 02 May 2012 - 03:57 AM
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?
This post has been edited by noriel: 02 May 2012 - 04:00 AM
Posted 03 May 2012 - 02:10 AM
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:
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 03 May 2012 - 03:33 AM
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.
This post has been edited by noriel: 03 May 2012 - 03:37 AM
Posted 03 May 2012 - 08:37 AM
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 03 May 2012 - 09:05 AM
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!
This post has been edited by noriel: 03 May 2012 - 09:06 AM
Posted 03 May 2012 - 04:43 PM
Cheers and Regards
- ← Renaming computer based on Serial number AND chassis Type
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- [Batch] Ping Script ? →