How to save .env file in windows? - windows

I tried to save file with .env file extension but I could not see any .env file extension in save as dropdown option.
I also tried to rename it as .env but it gets saved as text file (see screenshot) how can I fix this issue ?

If you use Windows, to save any file with an extension different from the default extension of the tool you are using, You have to select the option which appears like:
All Files or All Files (*.*) in the Type of File dropdown in the save dialogs.

Open your xx.env file with notepad++ and file -> saveas -> rename to .env and save

In windows normally you can not create a file without name. So to create a .env file there are three ways I know...
Copy paste from somewhere else
If you have installed php then run this command in console php -r "copy('anyfile.example', '.env');"
Create a txt file called anything.txt open CMD and find its dir then run ren anything.txt .env

Follow the steps below:
Open Notepad or Notepad++ and write the context in the file.
Notepad workspace screen with some context
Goto FILE-> SAVE AS
Save as Screen in the notepad
Select the All files()All files selection
Save the file with .env in the end.env extension
You've created .env file.env file
I've tried to create .env file in VS Code but it didn't work somehow. If you've any idea please let me know.

Steps to create .env file in Windows machine:
Open a Notepad and write the credentials inside the file
Click on Save option and change the file type to 'All files'
Keep the file name as .env
Hit Save
Now the file is an .env file. You can also check the file type in File Explorer to confirm.
One thing to remember is to put the file inside your Project directory where your code which accesses this .env file is stored.

You can open notepad
Type the information
go to file
click on save
change the file type to (.)

You can create a .env file in an IDE directly, like Visual Studio Code.
1.) Just right-click on the directory and create a new file.
2.) Name it as .env

Related

How to change the extention to all file in a directory using windows batch script

I need to change the file extensios of a directoy. If I do it manually so it will take more time. So is there any windows shell command or batch file to do this?
Like all .html file in a folder will be .php?
make a .bat in a folder and put in it this code
#ren *.Old_extension *.New_Extension
Also if you want to change more extensions just copy the lane and paste it under edited like this
#ren *.Old_extension *.New_Extension
#ren *.Old_extension2 *.New_Extension2
Yes, You can easily do this Command Prompt
Suppose, You have a Folder so many .TXT files in your folder.
Open that folder and just press SHIFT + RIGHT click and select Open Command Windows here
After that type the following command to change all .txt file to .doc
ren *.txt *.doc
It will change all text files in doc file
That's all

"You must type a file name" error thrown, when I create a .gitignore file on Windows

When I try to do this, I get the following error:
Obviously, Windows Explorer doesn't allow me to create this type of file patterns. How can I overcome this problem?
In the File Explorer, the trick is to call your file .gitignore. and it will remove the ending .
A strange behavior but, hey!, it works 😅
Or create it from a text editor...
Windows Explorer doesn't allow you to create files that consist essentially of a file extension only. This is because Windows Explorer has the option to hide file extensions, leaving you with a file you cannot see (see Why doesn’t Explorer let you create a file whose name begins with a dot?). This is not a restriction of Windows itself, or the file system in use, though.
To create a file named .gitignore, you will have to use another tool to create it. A common solution is to create a text file (e.g. test.txt), open it in Notepad, and select Save As... to rename the file to .gitignore.
The Windows command interpreter also allows you to create files without imposing the additional restrictions of Windows Explorer. A more direct solution would then be to create the file from the command line. This can be done using the following command:
copy NUL .gitignore
Note: When dealing with files that don't have a name, it's helpful to disable the option "Hide extensions for known file types" in Windows Explorer. Otherwise Windows Explorer might show files with no names, or hide them altogether.
In cmd, just type
echo. 2>.name_you_want
or
. 2>.name_you_want
to create a file.
If creating a directory, just type
mkdir .folder_name_you_want
Use command line instead.
I was also having the same error. The problem was . at the start of file or folder name.
So I created it by command line.
You can do this with command prompt for folder creation:
mkdir .folder_name

How to create a txt with file names and save it to same folder with Automator on OSX?

I want to make a .txt file inside the same folder that contains all the filenames of said folder.
How can i do that?
Thanks.
you can do this in terminal by using
ls {DIR} >> {FILE}
for example if i wanted to write a file called 'ls.txt' of all the files on the desktop i could use
ls /Users/corvinmcpherson/Desktop/ >> /Users/corvinmcpherson/Desktop/ls.txt
you can also create one using automator like this:
Or you can create an Automator Workflow like this as a Service, so that all you have to do is right click the folder, click the service and this text file will appear in the folder, with the name of the folder.

Executing binary files with a shebang

I created a simple program that takes the path of a directory as an input, creates an archive of that directory (converting it into a single file), adds a shebang to that file (so that the contents of the file can be easily extracted), and writes the file to the base directory of the specified path.
The problem is that the file does not extract itself when I double click on it. Instead the operating system (I'm using Ubuntu 11.10) tries to open it with gedit. This obviously shows the shebang, random gibberish, and the contents of the archived files.
I made the file executable, first by using chmod +x; and when it still didn't work I tried chmod 777. However it still refuses to execute the file with the shebang when I double click on it. Perhaps this is because it's not a pure text file.
Interestingly when I try to execute the file directly from command line it reads the shebang and extracts the contents of the archive properly. So there's nothing wrong with my file format. I don't know much about what operating systems do when you double click on a file but I would sure like to understand.
It surely makes no sense to add a shebang to a file if you still need to manually execute it from the command line. One advantage could be that you don't need to specify the program to open it with but I believe that's hardly an advantage. Any help will be greatly appreciated.
Update 1:
The program that creates the archive is called opm. It can be installed via the node package manager using the following command:
npm install opm
After that you simply use opm to pack and unpack directories for you. For example if I have a directory called test in my home directory then I can open a terminal and execute the following command to pack it:
opm test
This will create an archive of the directory called test.pack in the home directory. The .pack file has the shebang #!/usr/bin/opm. Opening a file with the extension .pack with opm tells it that it's an archive and opm unpacks it in the same directory.
Note: Change the name of the test.pack file if you do not want it to overwrite your existing test directory.
I added the shebang to the .pack file so that it would extract itself when I opened it. However that doesn't seem to work. Nevertheless if I run one of the following command then it works:
./test.pack
You may check my source code and make any modifications to the program as you may wish to.
Update 2:
Alright I created the following .desktop file for opm and stored it in the $HOME/.local/share/applications/ directory:
[Desktop Entry]
Type=Application
Version=1.0
Encoding=UTF-8
Name=OPM
GenericName=Object Packer and Minifier
NoDisplay=true
Comment=JavaScript Package Manager
TryExec=opm
Exec=opm %f
Terminal=false
MimeType=application/opm
Now I was able to associate .pack files with opm by right clicking on a .pack file, going to the Properties window, the Open With tab, and setting opm.desktop as the default application. Now I am able to unpack a .pack file by simply opening it.
However I would like to know how to associate .pack files with the mime type application/opm. Currently the .pack files are associated with application/x-java-pack200. How do I do so? Is it better if I use a different extension (e.g. .opm)? By associating the packed archives with the mime type application/opm will the OS open them with opm by default without having to explicitly set a default application from Properties > Open With?
If there's already a MIME-type associated with .pack then you'll want to use a different extension (.opm) to associate with your MIME-type (application/opm). The way you automatically associate a program that opens files of a specific MIME-type is with xdg-mime .
Alternatively,
Edit ~/.local/share/applications/mimeapps.list and put your MIME/application combo under [Default Applications] like so:
[Default Applications]
application/opm=opm.desktop;
Place your opm.desktop file in ~/.local/share/applications/ folder. (You've already done this)

Working with htaccess files on Windows - actually save file as .htaccess?

When working with htaccess files on Windows, is it possible to save the file as .htaccess ? (Rather than having to rename on LAMP server)
You can use the Windows command line or Powershell to rename a file, or you could simply go to the desired directory and make it with notepad .htaccess. It'll prompt if you want to create the file, click "yes," and you're done.
Use notepad, save the file as ".htacess" using double quotes around the name to ignore illegal characters.

Resources