To check if a path is a Directory in Python you can use the snippet below.
Sample Python
import os print(os.path.isdir("/myfolder/folder1"))
To check if a path is a Directory in Python you can use the snippet below.
import os print(os.path.isdir("/myfolder/folder1"))
To check if Folder exists in Python you can use the snippet below.
import os print(os.path.exists("/myfolder/folder1"))
To read a file to string in Java you can use the following snippet.
public static string readFileToString(FileInputStream _fileInputStream) { try { DataInputStream dataInputStream = new DataInputStream (_fileInputStream); byte[] Bytes = new byte[dataInputStream.available ()]; dataInputStream.readFully (Bytes); dataInputStream.close (); String result = new String (Bytes, 0, Bytes.length, "Cp850"); return result; } catch (Exception e) { e.printStackTrace(); return ""; } }
To process all files in a directory in Python you can use the following snippet.
import os for filename in os.listdir(dirname): # do something pass
To check if a file exists in C++ you can use the following snippet.
#include <sys/stat.h> inline bool fileExists (const std::string& fileName) { struct stat buff; return (stat (fileName.c_str(), &buff) == 0); }
To check if a file exists in C you can use the follwing snippet.
#include <unistd.h> int fileExists(const char *filename) { return !access(filename, F_OK); }
To reset the windows audio mixer in Batch you can use the following snippet.
This snippet will set all volume levels equal. If you know a simpler way to reset the audio mixer, without setting all volume levels manually please let us know.
@ECHO OFF ECHO Resetting Volume Mixer Settings! NET STOP Audiosrv NET STOP AudioEndpointBuilder REG DELETE "HKCU\Software\Microsoft\Internet Explorer\LowRegistry\Audio\PolicyConfig\PropertyStore" /F REG ADD "HKCU\Software\Microsoft\Internet Explorer\LowRegistry\Audio\PolicyConfig\PropertyStore" NET START Audiosrv
To list the avaiable fonts in Java you can use the following snippet.
GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment(); String fonts[] = g.getAvailableFontFamilyNames(); for (int Counter = 0; Counter < fonts.length;Counter++ ){ System.out.println(fonts[Counter]); }
To delete a file in Ruby you can use the following snippet.
File.delete('filePath')
To rename a file or folder in Ruby you can use the following snippet.
begin File.rename("/path/to/oldfile", "/path/to/newfile") rescue Exception => e # the exception your way end