Dynamically picking up the file name in bat file - windows

I am running a bat file in different users laptops
Some users having this path C:\Users\%USERNAME%\AppData\Local\Google\1.8.0
some users having this path C:\Users\%USERNAME%\AppData\Local\Google\1.9.0
In my bacth file --I used only the path C:\Users\%USERNAME%\AppData\Local\Google\1.8.0
for users which are having 1.9.0 this code is not working.
Please advise

Looks like your script is using user profiles folder structure :
C:\Users\%USERNAME%\AppData\Local
This can be acheived using %localappdata% instead :
so in your script you can do as below :
CD %localappdata%
if exist Google\1.8.0 CD Google\1.8.0
if exist Google\1.8.0 CD Google\1.9.0
And then rest of your script will be same
Above code would first CD to Local folder and then search for required folder structure rest you can play with i beileve

Use a Find-n-Replace-across-files feature from a tool such as Notepad++ and change the path to whichever is the correct path for the laptop you are running from. Or if you want a batch file for that, the Find Replace tool https://findandreplace.codeplex.com/ can help. If you are doing this often, then you might want to consider AutoIT to develop your own additional script. Or, then, Python.

Related

Unable to create /root/.config/<app> programmatically

I've built a script that places an icon in the launcher to open a program as the root user. This script also adds NOPASSWD to the user's configuration for this specific app in /etc/sudoers, however the one part of the script that refuses to work is the creation of the profile in /root/.config/<app>. I can create this manually, using the same mkdir command, but when I place the same command in the script it returns no such file or directory. I have replicated this behaviour a number of times, including on a clean install.
Is there some form of protection that disallows the ability to automate the creation of this directory? Or am I missing something about hidden folders in Linux?
I assume you are doing this when the .config dir does not exist yet.
mkdir /root/.config/<app>
Try this :
mkdir -p /root/.config/<app>
This will create any missing parent directory to the full path you provide.

File Deletion Automated in Windows

We have following requirement.can anyone please help me to write bat script? if you have the script already for my requirement it would be very much appriciated.
1.Input text file will be uploaded manually in the server path e.g: E:\usr\sap\python\input.txt
2.SAP job will create output.txt in the same server path e.g: E:\usr\sap\python\output.txt
3.Once the ouput.txt is generated, that should be copied to archive folder e.g: E:\usr\sap\archive\ouput.txt
4.Once it is moved to archive folder with time stamp, the script should delete all the files in the path E:\usr\sap\python
How about this. Rather than give you the direct programming, let me guide you with a basic flow. A very simple script can do this....
Check if the file exists in the output folder.....
a. If it exists....delete the file you want
b. If it is not there.....restart the script
This is better done with something like Visual Basic and may not be entirely possible with a batch script.

Windows environment variable issue

I have two environment variables defined as:
test1=C:\something\dir1
test2=C:\something\dir2
And I'm trying to run the following command:
copy dir1\filename.txt dir2\filename.txt
I know that if I write the copy command with the environment variables it will work, like below:
copy %test1%\filename.txt %test2%\filename.txt
But isn't there a better way to do this? If Windows doesn't find the "dir1" directory in its current directory, won't it try to find it with the system variables it has?
EDIT: Im trying to use the copy command without typing the enviroment variable's name in the command.
Something like "copy dir1\filename.txt dir2\filename.txt", where, if Windows cant find the dir1 directory in its current directory, it would automatically search this directory with the enviroment variables. Is this possible?
This will copy the fully qualified path and filename, and cater for spaces etc.
copy "%test1%\filename.txt" "%test2%\"
If it doesn't work for you then edit your question and give more details about the task.

ISTool command line problems

I am trying create installation file for my projects.
I am using command line so I created bat file "create_setup.bat". From this file I am trying to compile Inno Setup script "my_project_setup.iss":
"ISTool.exe" -compile "Subfolder1\Subfolder2\my_project_setup.iss".
Important: "create_setup.bat" - located at the folder "WorkFolder" and Inno Setup script "my_project_setup.iss" located at the folder "WorkFolder\Subfolder1\Subfolder2".
But I don't have any good results, no installation file.
However if I running "create_setup.bat" from the same folder as script "my_project_setup.iss" located it's work correct (of course path at the file create_setup.bat to the script my_project_setup.iss was changed).
At the script "my_project_setup.iss" I have tried to change Inno Setup property "OutputDir" but it's not help.
Inno Setup property "Source" I have not changed.
Can you change your script so that you CD to the subfolders before calling ISTool.exe?
PUSHD "Subfolder1\Subfolder2"
ISTool.exe -compile my_project_setup.iss
POPD
Try that and see if it works better, it could have something to do with any relative paths you might have inside of your .iss file.

Relative file paths

I am trying to read in from a few files using something like this
IO.foreach("TeamFields.txt") { |line| fieldNames.push(line.chomp) }
It works fine when running the from the command line, but when I package to an .exe with shoes and run it can't find the file. Is there a way to specify a path relative the the .exe or do I have to provide the full filepath (e.g. "c:\files\TeamFields.txt")? Thanks for the help.
This is because your executable is not run with the correct current directory.
Either fix the current directory (for example in the shortcut) or modify your Ruby program to automatically set the working directory to the program directory with:
Dir.chdir(File.dirname($PROGRAM_NAME))
You need to set "Current Application Directory" correctly before going relative.
The user can execute your app with different start up dir, or system can call your app with different dir.
If files in question are in the folder of your app, the only thing you need to do is to get that folder, and set it to be current.
I don't program in ruby, but I do with windows, and odds are the relative path will be based on the location of the .exe file.
So, yes, you're probably better off passing a full path for the file name.
The constant __FILE__ will contain the full path to the currently executing file. You can then use methods of the File class to strip off the filename, append the relative path for whatever other file in your package it is you want and resolve the result.

Resources