Tag: directory

Java

Check if file or directory exists in Java

Check if file exists: File f = new File("/path/to/filename"); if(f.exists()){ .. }File f = new File("/path/to/filename"); if(f.exists()){ .. } Check if directory exists: File f = new File("/path/to/folder/"); if(f.exists() && f.isDirectory()){ .. }File f = new File("/path/to/folder/"); if(f.exists() && f.isDirectory()){ .. }

PHP

List files in directory – PHP

$dir = ‘/path/to/dir/’; if(is_dir($dir)) { if($handle = opendir($dir)) { while(($file = readdir($handle)) !== false) { if($file != "." && $file != ".." && !is_dir($file)) { echo $file.'<br>’; } } closedir($handle); } }$dir = ‘/path/to/dir/’; if(is_dir($dir)) { if($handle = opendir($dir)) { while(($file = readdir($handle)) !== false) { if($file != "." && $file != ".." && !is_dir($file)) …

Python

How to mark directory on disk as a Python package

To mark a directory as a Python package directory you have to put a file named __init__.py in this directory. for example, myproject/libraries/__init__.py myproject/libraries/mymodule.py myproject/main.py you can import mymodule.py in main.py as: import libraries.mymodule or from libraries import mymodule The __init__.py file is usually empty.

Python

Create images thumbnails with Python

import glob import Image dir="/home/username/Pictures/"   for infile in glob.glob(dir+"*.jpg"): imgfile=infile[(infile.rfind("/")+1):] if infile[0:2] == "thumb_": continue try: img = Image.open(infile) img.thumbnail((128, 128), Image.ANTIALIAS) img.save(dir + "thumb_" + imgfile, "JPEG") except IOError: img=Noneimport glob import Image dir="/home/username/Pictures/" for infile in glob.glob(dir+"*.jpg"): imgfile=infile[(infile.rfind("/")+1):] if infile[0:2] == "thumb_": continue try: img = Image.open(infile) img.thumbnail((128, 128), Image.ANTIALIAS) img.save(dir + …

Brute-force, Enumeration, Network, Tools

Brute force directories and files names on web application

OWASP DirBuster is a multi threaded java application designed to brute force directories and files names on web application servers. DirBuster will attempt to find hidden pages and directories with a web application. Comes with a total of 9 different lists and it is extremely effective at finding hidden files and directories. It also has …

Microsoft Windows, Python

List files and folders in a directory – Python

Let’s see an easy way to list all files and folders in a directory: import os   for filename in os.listdir("x:\mydir1\mydir2\"): print(filename)import os for filename in os.listdir("x:\mydir1\mydir2\"): print(filename) Open command line, change to the directory of your python file and issue the following command: python myfile.pypython myfile.py

Linux, Ubuntu

List files with absolute path recursive in linux

Let’s see how we can list all files of a directory recursive in linux. First of all install tree command tool. For Ubuntu users just issue the following command: sudo apt-get install treesudo apt-get install tree List all files recursive: tree -if /path/to/directory/tree -if /path/to/directory/ explaining: -i Don’t print indentation lines. -f Print the full …

C#, Microsoft Windows

Monitor Directory for Changes

FileSystemWatcher is a class in .Net that listens to the file system change notifications and raises events when a directory, or file in a directory, changes. You can monitor a single file or a directory for changes and get notified about those changes. With FileSystemWatcher class you can monitor for new files creation, files editing, …

Apache, Linux

Securing Apache Part 1

The following tips are things you can do to make your apache server more secure. Before you begin to follow the tips below, locate your apache’s configuration files first. Common places for apache’s configuration files are: /etc/apache2/apache2.conf, /etc/apache2/httpd.conf and /etc/apache2/sites-enabled/000-default. Before you make any changes, MAKE BACKUP COPIES OF YOUR FILES. Here we go: 1. …