working on it ...

Filters

Explore Public Snippets

Sort by

Found 11k snippets matching: directory

    public by lbottaro  901646  60  8  1

    How to remove all checked out files in clearcase

    This cleartool command lists all the checkout files (both from the current directory and from the entire view) searching in each directory or vob path. For each element found, it invokes the command to remove the checkout.
    # Remove ALL checked out files from view in the entire vobs
    cleartool lsco -cview -me -avobs -short | xargs cleartool unco -rm 
    
    # Remove ALL checked out files from the current directory on only
    cleartool lsco -cview -me -rec -short | xargs cleartool unco -rm 

    public by lbottaro @ Amazon_AWS_Python_API  304436  0  8  0

    Amazon S3 Aws - How to download a file from a bucket to a target directory

    This code shows how to download a file from an existing bucket invoking the boto python API, saving to a target directory. You need to specify the filename and path where to save the data. [How to create a bucket](http://www.snip2code.com/Snippet/4892/Amazon-Aws-S3---Creating-a-bucket-in-pyt) [How to upload a file to a bucket](http://www.sn
    # This downloads the object foobar.pdf and saves it in /home/luca/documents/
    
    key = bucket.get_key('foobar.pdf')
    key.get_contents_to_filename('/home/luca/documents/foobar.pdf')

    public by cghersi  264226  2  5  0

    Bash command to get current directory

    VAR_NAME=$(pwd)

    public by lbottaro  247353  3  7  0

    Lock and synchronization in python

    This example shows how to deal with lock in python parallel programming. Here we want to calculate the disk occupancy for a given directory in Linux OS, evaluating the disk occupancy for any subdirectory using threads. Note the usage of lock mechanism to ensure atomic operation on the total sum.
    import os
    import string
    import threading
    from threading import Thread
    
    disk_usage = 0
    lock = threading.Lock()
    
    for dir in os.popen('ls -d *').readlines():
        print "Dir: " + dir
        t = Thread(target=methodToBeExecutedInParallel, args=(dir,))
        t.start()
        #Join all existing threads to main thread.
        for thread in threading.enumerate():
            if thread is not threading.currentThread():
              thread.join()
        print "Disk usage = " + str(disk_usage)
    
    # Function invoked by each thread
    def methodToBeExecutedInParallel(directory):
        print "Working on dir = " + directory
        cmd = 'du -s ' + directory
        line = os.popen(cmd).readlines()[0]
        dirUsage = int(line.split()[0])
        print "Acquiring lock for "+directory+"..."
        with lock:
            print "Acquired lock for "+directory
            global disk_usage
            disk_usage += dirUsage
        print "Disk usage = " + str(dirUsage)

    public by Charles Peter Nystrom  202164  3  3  0

    Replace string in all files within the current directory. - PowerShell

    Replace string in all files within the current directory. - PowerShell: gistfile1.txt
    $stringToReplace = "foo"
    $replaceWith = "bar"
    Get-ChildItem | ForEach-Object{ $pathToFile = $_.FullName; (get-content $pathToFile) | % { $_ -replace $stringToReplace, $replaceWith } | set-content $pathToFile }
    
    

    public by DanielOgbuagu  201740  1  5  0

    Adding a *.jar file (originating from java-wrapped C++ code) to an SBT project classpath

    I thought using unmanaged dependencies in SBT projects was simply dropping a jar file into the lib directory, until I bought an SDK for a biometric device. Both the C++ and the Java packages were provided. I opted for the Java package, copying the provided jar file and the JNI (*.so) files into the appropriate locations and configuring the ja
    /**
     * In my <code>build.sbt</code> file, I appended a blank line and then the following:
     */
    
    libraryDependencies += "groupID" % "artifactId" % "revision" from "file:///home/Danogbuagu/Projects/biometric-lib/filename.jar"
    
    // where,
    // groupID for example is like: com.zigzagcompany 
    // artifactId for example is like: zigzag
    // revision for example is like: 1.3.4
    // Remember the line befor the code and that after.

    public by lbottaro  7058  1  7  3

    Linux one liner bash code to detect file or directory from a given list

    This bash code shows how to detect if a given item in a list returned by a command is actually a file or a directory, without affecting the output format. In this case, xargs is used to pass the '{}' reference to a shell script executed for each line returned by the tree command.
    tree -if --noreport /home/ | xargs -I '{}' sh -c 'if [ -d {} ]; then echo "Dir {}"; else echo "File {}"; fi'  

    public by lbottaro  4472  0  7  0

    How to find and remove directories in windows batch command

    The script will search for a given path and returns the name of folders found. The script may remove the directory found (with or without prompt)
    @echo off
    set m_path="C:\Users"
    if exist %m_path% (
    cd %m_path%
    echo FOUND %m_path%
    REM pippo
    for /F %%i in ('dir obj /s /b') do (
    echo "dir %%i"
    REM Remove dir without prompt
    rmdir %%i /s /q
    REM Remove dir with prompt
    REM rmdir %%i /s
    )
    )
    
    pause

    public by bobby  24516  0  3  0

    Lints all PHP files recursively from a starting directory

    Lints all PHP files recursively from a starting directory: Recursive PHP Lint
    find ./ -type f -name \*.php -exec php -l {} \; | grep "Errors parsing ";
    
    

    public by MarcoDeMagistris  2538  0  6  0

    DirectoryStream - list all the contents of a directory

    You can list all the contents of a directory by using the newDirectoryStream(Path) method. Added a Directory Filter.
    public class myLogDirectory{
    	
    	/**
    	 * It is a inner class used to create a Directory Filter 
    	 * @author emadema
    	 *
    	 */
    	public static class  myFileFilter implements DirectoryStream.Filter<Path>{
    		@Override
    		public boolean accept(Path path) throws IOException {
    			return (Files.isDirectory(path)); //List only directory	
    			//return false;
    		}
    	}
    
    	/**
    	 * Find subfolders in @param directoryname and
    	 * creates filelist structure
    	 * 
    	 * @throws IOException
    	 */
    	public void DirectoryList(String directoryname) throws IOException{
    		DirectoryStream<Path> stream = Files.newDirectoryStream(new File(directoryname).toPath(), new myFileFilter());		
    		for (Path entry: stream)
    			System.out.println(entry.getFileName().toFile());
    	}
    		
    	
    	public static void main(String[] args) {
    		try {
    			new myLogDirectory().DirectoryList("c:\\test");
    		} catch (IOException x) {
    			System.err.println(x);
    		}
    	}
    	
    }
    • Public Snippets
    • Channels Snippets