Tag Archive for files

Remove Folders from a Directory

rm -rf directory/{folder_a,folder_b}

source

Browse for file and upload

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();">
<mx:Script>
<![CDATA[

private var urlRequest:URLRequest;
private var fileReferenceList:FileReferenceList;
private var serverSideScript:String = "http://localhost/uploadFile.php";

private function init():void {
urlRequest = new URLRequest(serverSideScript);
fileReferenceList = new FileReferenceList();
fileReferenceList.addEventListener(Event.SELECT, fileSelectedHandler);
}

private function uploadFile():void {
fileReferenceList.browse();
}

private function fileSelectedHandler(event:Event):void {
var fileReference:FileReference;
var fileReferenceList:FileReferenceList = FileReferenceList(event.target);
var fileList:Array = fileReferenceList.fileList;

// get the first file that the user chose
fileReference = FileReference(fileList[0]);

// upload the file to the server side script
fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler);
fileReference.upload(urlRequest);

// update the status text
statusText.text = "Uploading...";
}

private function uploadCompleteHandler(event:Event):void {
statusText.text = "File Uploaded: " + event.target.name;
}

]]>
</mx:Script>

<mx:Label text="Upload File From Flex to PHP" fontWeight="bold"/>
<mx:Label text="Choose a file..." id="statusText"/>
<mx:Button click="uploadFile();" label="Upload File"/>

</mx:Application>

source

Recursively unlock files in Mac OS X

chflags -R nouchg *

source

Extract the extension of a file from a full pathname

public static String getFileExtension(String fileName) {
File tmpFile = new File(fileName);
tmpFile.getName();
int whereDot = tmpFile.getName().lastIndexOf('.');
if (0 < whereDot && whereDot <= tmpFile.getName().length() - 2 ) {
return tmpFile.getName().substring(whereDot+1);
}
return "";
}

source

copy directory (unix)

cp -R /verzsource/ /target

source

Recurse through directories and files

Dir['**/*.jpg'].foreach do |filename|
... process your filename here
end

source

Get all files from a folder for form

<form method="POST" name="imageForm">
<select name="images">
<?
$handle=opendir('../images/');
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<option value="$file">$file   - ".filesize("../images/$file")." bytes</option>
";
}
}
closedir($handle);
echo "</select>";
?>
</form>

source

C Console Scripting Framework

#include <stdio.h>
//#include <stdlib.h> //for system pause

//USAGE (in DOS):   dir blah | yourProgramName > outFile.txt
// (use /b for JUST file and folder names)
// (use /b /ad for JUST folder names)

void printsln(char *s) {printf("%s
", s);}

void error(char *s){printsln(s); exit(1);}

bool ngets(char *s, int n) {
int i = 0;
char c;
c = getchar();
if (c==EOF) {s[i] = 0; return false;}
while(c!='
'){
if(i>=n) error("input stream overflowed buffer");
s[i++] = (char)c;
c = getchar();
}
s[i] = 0;
return true;
}

int main(int argc, char *argv[])
{
char s[10000]; //note: possible (in theory) security hole
while(ngets(s, 10000)) { //security hole closed.

printf("/new/%s
", s, s);  //TWEAK THIS LINE!!!

}
//system("pause");
return 0;
}

source

Batch rename files in directory

for F in * ; do NF=`echo $F | perl -lne "s/ /_/g; s/._/./g; s/[',-]//g; print lc"` ; mv "$F" "$NF" ; done

source

batch rename files

for FILE in * ; do NEWFILE=`echo $FILE | sed 's/-//g'` ; mv "$FILE" $NEWFILE ; done

source