w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
While Sending Html Mails from my web application Recieved Mails contains Symbols like &ldquo,&rdquo, ‘
Check with another constructor for htmlView: ContentType mimeType = new System.Net.Mime.ContentType("text/html"); var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, mimeType);

Categories : Asp Net Mvc

How to create a bash script that will lower case all files in the current folder, then search/replace in all files?
Something like this should work: #!/bin/bash for file in *.html do lowercase=`echo $file | tr '[A-Z]' '[a-z]'` mv "$file" "$lowercase" for f in *.html do sed -i "s/$file/$lowercase/g" "$f" done done Change *.html to *.<extension> if you're working with something other than html files.

Categories : Bash

The Command-T how to use current file own NERDTree bookmark as search directory?
Completely disregarding NERDTree, you can configure your CommandT mapping to include your project root by default. To make it flexible, you can load the project root for each vim session dynamically from an environment variable: "If the $H environment variable is available, assume it contains CommandT's root dir if !empty($H) nnoremap <silent> <Leader>t :CommandT $H<CR> else nnoremap <silent> <Leader>t :CommandT<CR> endif Or more simply, you could use $PWD, which should reflect the directory you started your vim session in. Regarding the solution you propose, you can indeed cd in NERDTree by position the cursor on the node you want to cd to and then pressing cd (see :h NERDTree-cd). That changes the output of :pwd/:!pwd for the NERDTree buffer an

Categories : Vim

Zip together all HTML files under current directory
What about this? find /your/path/ -type f -name "*.html" | xargs zip all_html_files.zip looks for all .html files under the directory /your/path (change it for yours). Then, pipes the result to xargs, which creates the zip file. Edit To junk the paths, add -j option: find /your/path/ -type f -name "*.html" | xargs zip -j all_html_files.zip

Categories : Linux

How do I make FindFirst look for files in the current directory?
The path '*.*' is relative to the root directory of the drive of the current working directory. You probably mean to pass GetCurrentDir + '*' to FindFirst. Or even better, TPath.Combine(GetCurrentDir, '*'). For example, this program demonstrates that you code works correctly provided that you pass an appropriate path to FindFirst. program FindFirstDemo; {$APPTYPE CONSOLE} uses SysUtils, IOUtils; var SR: TSearchRec; begin Writeln(GetCurrentDir); if FindFirst(TPath.Combine(GetCurrentDir, '*'),faAnyFile,SR)=0 then begin repeat Writeln(SR.Name); until FindNext(SR)<>0; FindClose(SR); end; Readln; end.

Categories : Delphi

Geting numbers of files in specific directory in Linux
scandir() example, requires dirent.h: struct dirent **namelist; int n=scandir(".", &namelist, 0, alphasort); // "." == current directory. if (n < 0) { perror("scandir"); exit(1); } printf("files found = %d ", n); free(namelist);

Categories : Linux

Optimal procedure to rename files in a linux directory
for file in index.html?*; do new=${file/?/_} # Substitute underscore for ? mv "$file" "$new" # Rename the file done See the Parameter Expansion section of the bash man page for information on the substitution syntax used.

Categories : Regex

How do you get the total size of all files of a certain type within a directory in linux?
Found it. ls -lR | grep .jpg | awk '{sum = sum + $5} END {print sum}' As I understand it: ls says list all the files in the directory. Adding in the -l flag says show me more details like owner, permissions, and file size. tacking on R to that flag says 'do this recursively'. Piping that to grep .jpg allows only the output from ls that contains '.jpg' to continue on to the next phase. Piping that output to awk '{sum = sum + $5} END {print sum}' says take each line and pull its fifth column element (file size in this case) and add that value to our variable sum. If we reach the end of the list, print that variables value.

Categories : Osx

Print out all files in current directory and subdirectories in Python
It's only a little more difficult using os.walk import os for dirpath, dirnames, filenames in os.walk('.'): for f in filenames: print os.path.join(dirpath, f) You can also express this as a generator expression for filename in (os.path.join(dp, f) for dp, dn, fn in os.walk('.') for f in fn): # do something with filename

Categories : Python

How to execute files added to .bashrc out of current directory?
Here is the solution: Composer showed an error that I was running the CGI version of php (stupid I know, I know). That was because I had an symlink in my bin dir to the cgi version. I changed the link it shows now to the CLI version of php. Now it works :)

Categories : Linux

PHP loop through current directory files for image resize
There's two ways to solve this. You can use one of PHP's "Magic Constants," __PATH__ to show the path to that current file. However, ot all PHP installs have this built in. The function getcwd() returns the current directory you're looking at, which may not be where your file lives. You can try this: <?php chdir( dirname( __FILE__ ) ); echo getcwd(); ?> Once you pull the directory, you can feed it into your script as it is. Hope this helps.

Categories : PHP

Search for .txt, .scv files in directory in Python
There is a syntax error in your code - wildcards must be strings. And the second problem is that glob doesn't support brace expansion (i.e. it doesn't understand {txt, csv}). So you need to use basic wildcards: import glob def core(): old_path = '/home/demo/' txt_files = glob.glob(old_path+'*.txt') csv_files = glob.glob(old_path+'*.csv') print(len(txt_files + csv_files)) core()

Categories : File

Search a directory and all files within for a certain string
this worked for me through the command prompt: for /r %G in (*) do @find "import" "%~G" >nul 2>&1 && @echo %G EDIT: To see lines and numbers: for /r %G in (*) do @findstr /n "issue" "%~G" 2>null && @echo %G

Categories : Batch File

how to search for a word in multiple pdf files using pdftext in linux
The following should list the files matching the pattern: for i in `find . -type f -name "*.pdf"`; do pdftotext "${i}" - | grep -lq "search-word" && echo $i; done The -q option for grep prevents any output to STDOUT. -l lists matching files.

Categories : Linux

How can I manage Linux settings (config) files in different directories in a single Git repo in another directory?
You can use symlinks. It is indeed what dotfiles managers such as homesick do. It is helpful to have a script to generate all the links automatically for you, in case you want to clone your setup to another box.

Categories : Linux

How to I search for a text string and copy those files to another directory
for i in `ls -1tr` { SEARCH_STRING_LINE_NO=`grep -n SEARCH_STRING i | cut -d: -f1`; if [ SEARCH_STRING_LINE_NO > 0 ] then cp i folder_path_where_u_want_to_copy fi } Replace SEARCH_STRING with the text string you want to find. Replace folder_path_where_u_want_to_copy with the folder path where u want to move the files containing SEARCH_STRING This should copy the files containing SEARCH_STRING to the folder folder_path_where_u_want_to_copy I have not tested this code as I dont have a unix box with me right now, but atleast it should give u an idea to approach

Categories : Unix

Search in directory of files based on keywords from another file
It is a good idea to start your specs/question with a story ("I have a ..."). But such a story - whether true or made up, because you can't disclose the truth - should give a vivid picture of the situation/problem/task the reason(s) why all the work must be done definitions for uncommon(ly used)terms So I'd start with: I'm working in a prison and have to scan the emails of the inmates for names (like "Al Capone") mentioned anywhere in the text; the director wants to read those mails in toto order lines (like "weapon: AK 4711 quantity: 14"); the ordnance officer wants those info to calculate the amount of ammunition and rack space needed paragraphs containing 'family'-keywords like "wife", "child", ...; the parson wants to prepare her sermons efficiently Taken for itself, each of th

Categories : Linux

Python - search through directory trees, rename certain files
You need to use absolute filenames when renaming: os.rename(os.path.join(root, file), os.path.join(root, new_name)) You also do not appear to be looping over the files list; add another for loop: for root, subs, files in os.walk("."): for file in files: You may want to avoid using file as a name, it shadows the built-in type. Perhaps filename is a better choice?

Categories : Python

Search in directory to find files with certain file extensions
Use glob() function: foreach (glob("*.{pdf,mp3}", GLOB_BRACE) as $filename) { echo "$filename "; } ◾GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c'

Categories : PHP

Extend PowerShell to search/replace and perform on all files in directory?
Try this: import-csv .chapters.csv | ConvertTo-Json -Compress | Foreach {$_ -creplace 'NULL','null'} | Out-File .chapters.json The -replace operators can be used to replace text within a string.

Categories : Powershell

How can I search a directory of files using static methods and return an object?
The problem is that you don't add the result from the recursive call. Change: if(file.isDirectory()) { search(file, p); } to if(file.isDirectory()) { dataInFile.addAll(search(file, p)); }

Categories : Java

Linux: Move log files from a mounted dir to a local dir recursively while maintaining directory structure in local direcoty
How about something like rsync -azrR --include='*.log' -f 'hide,! */' /media/primary /backup If you use man rsync and type 2343g it should take you to the line where it explains this filter. Basically it will hide everything that's not a directory (every file) from the pattern matching; however, since I've used the --include='*.log' flag as well it will override that and the pattern will match only .log files. You can also use the -nv flag to do a dry run and see what would happen.

Categories : PHP

Using batch files to copy all files from a directory tree to a single directory
@echo off set "COPY_FROM=C:UsersmeDesktopDisc 1" set "COPY_TO=C:Testing est" md "%copy_to%" 2>nul cd /d "%COPY_FROM%" for /f "delims=" %%a in ('dir /b /s /a-d') do copy "%%a" "%COPY_TO%" pause

Categories : Batch File

How to change the current working directory to a specific directory and execute a program under the specific directory?
One of your principal problems is that you don't capture the return value (output) of the command in backticks. You are merely throwing away the output you want. Do something like: my $output = `perl ./script.pl` system("perl ./script.pl")

Categories : Perl

Python joining current directory and parent directory with os.path.join
You can use normpath, realpath or abspath: import os goal_dir = os.path.join(os.getcwd(), "../../my_dir") print goal_dir # prints C:/here/I/am/../../my_dir print os.path.normpath(goal_dir) # prints C:/here/my_dir print os.path.realpath(goal_dir) # prints C:/here/my_dir print os.path.abspath(goal_dir) # prints C:/here/my_dir

Categories : Python

Gallery Is Missing Files From Directory- How To Retrieve All Files From Directory
An alternative approach you may want to use to secure your list of thumbnails: $directory = 'thumb'; //where the gallery thumbnail images are located $files = glob($directory."/*.{jpg,jpeg,gif,png}", GLOB_BRACE); natsort($files); //sort by filename Then to render it out simply do this: <?php for($x = 0; $x < count($files); $x++): $thumb = $files[$x]; $file = basename($thumb); $nomargin = $x%4 == 0?" nomargin":""; $title = htmlspecialchars($file); ?> <div class="thumbs fancybox<?= $nomargin ?>" style="background:url('<?= $thumb ?>') no-repeat 50% 50%;"> <a rel="group" href="images/'.<?= $file ?>" title="<?= $title ?>"><?= $title ?></a> </div> <?php endfor;

Categories : PHP

After I deleted a directory, it always prompts "shell-init error retrieving current directory getcwd solve" when log on bash
When opening a new shell or xterm, it's started in the working directory of the process that started it. If you e.g. cd /proc && xterm, the new terminal will place you in /proc. Whatever's starting your terminal had positioned itself in /home/desktop/zeno, and now all the terminals are trying to start there. If you make that process change directory (by rebooting, for example), the terminals will start in a directory that exists and you will no longer get this error.

Categories : Linux

How to print the name of my current directory's parent directory
You can use ${PWD%/*}: $ echo $PWD /home/me/test/t $ echo ${PWD%/*} /home/me/test As the expression ${string%substring} Strips shortest match of $substring from back of $string (reference).

Categories : Shell

multiple search key for binary search tree in linux C
Well, in a binary tree, key's only make sense in relation to each-other. Meaning that key1_a makes sense in the left branch only if key1_b is larger/smaller in the right branch (depending how you structure it). If you had a tree of two set of keys, hypothetically they could be in the same tree data-structure if they had the same proportions. As in, if each key in key2 was exactly 50 above key1. But that wouldn't really be useful at all. The only idea I have is making it so there are some null value keys. So that if you're traversing your tree and you're at a leaf of key1 but not key2, you just keep going, and the rest of the tree lower down will have a null value (maybe -1?) in the key, or will have a boolean trigger making it so key1 is no longer present in this branch of the tree. It's

Categories : C

Get the current directory name via php script in another directory
I am not 100% sure of your questions, but it sounds like you are looking for the URL/Directory of the page you are currently on, not the directory of the header? What about: $_SERVER['PHP_SELF']; $_SERVER['REQUEST_URI']; $_SERVER['SCRIPT_NAME']; $_SERVER['SCRIPT_FILENAME']; $_SERVER['DOCUMENT_ROOT']; Those all give info about the current file open by the server based on the HTTP request it received.

Categories : PHP

Moveuploaded files function in PHP moves the file to the temp directory but not to the destination directory
First time you called move_uploaded_file() you moved that file from temporary folder to $workDir. After that, uploaded file no longer exists in temporary directory. Just use rename() function to move that file from $workDir."/".$tmpName to final destination. // moves file from workdir to final destination rename($workDir."/".$tmpName, $_POST['filetype'].'/'.$rightname);

Categories : PHP

Makefile: copy perl/python files from source directory into build directory
Basically, when you run make X, you are telling Make to find target X in your Makefile. So if you have no install: target, nothing will happen. All of this really depends what is in your Makefiles. If you want to copy your perl/python files into the build directory, one way to do so is to write a Makefile target that runs a *sh command like mv dir2/*.pyc build; mv dir2/*.pl build, and require that target somewhere else in your Makefile. If you need a good Makefile tutorial, here's one that I started with.

Categories : C++

getting the full filenames from all top directory files in a specific directory and suppressing the occuring error
Did I understand correctly that you only need the File-names with directory-names. This code works for me, no elevations needed. private void button1_Click(object sender, EventArgs e) { string folder = @"C:windowsprefetch"; string filemask = @"*.pf"; string[] filelist = Directory.GetFiles(folder, (filemask)); //now use filelist[i] for any operations. }

Categories : C#

How do I enumerate through a directory in Objective-C, and essentially clear out all the directories of non-directory files?
Something like this will work: NSURL *rootURL = ... // File URL of the root directory you need NSFileManager *fm = [NSFileManager defaultManager]; NSDirectoryEnumerator *dirEnumerator = [fm enumeratorAtURL:rootURL includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey] options:NSDirectoryEnumerationSkipsHiddenFiles errorHandler:nil]; for (NSURL *url in dirEnumerator) { NSNumber *isDirectory; [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:NULL]; if (![isDirectory boolValue]) { // This is a file - remove it [fm removeItemAtURL:url error:NULL]; } }

Categories : Objective C

How can I copy only files and folder created in the past hour in one directory to a new directory?
Robocopy doesn't have the granularity, but XXcopy seems to handle it. /DA#30m selects files made within the last 30 minutes. XXcopy is free for non commercial use and can be downloaded from http://www.xxcopy.com XXcopy is xcopy on steroids.

Categories : Batch File

Copy files from source directory to target directory and exclude specific file types from specified directories
This is one way to do it $SourceDirectory = 'C:Source' $DestinationDirectory = 'C:Destination' $ExcludeExtentions = '*.txt*', '*.xml*' $ExcludeSubDirectory = 'C:Sourcead_directory1', 'C:Sourcead_directory2' Get-ChildItem $SourceDirectory -Recurse -Exclude $ExcludeExtentions | Where-Object { $ExcludeSubDirectory -notcontains $_.DirectoryName } | Copy-Item -Destination $DestinationDirectory Your best friend here is Where-Object, or where. It takes a scriptblock as parameter and uses that scriptblock to validate each object that goes through pipeline. Only objects that make script return $true are passed through Where-Object. Also, take a look at the object that represents a file you get from Get-ChildItem. It has Name, Directory and DirectoryName containing pieces of file's FullNam

Categories : File

Import a directory with files and force-overwrite even if the directory already exists
Read svn help import and use it. If you task really is Add unversion tree from custom location into existing repository svn import /PATH/TO/PROJECT protocol://URL/IN/REPOSITORY will add as result Project as child to URL/IN/REPOSITORY Just to note: import will appear as commit in repository

Categories : Svn

not found [No such file or directory] error, even though the file present in that directory on RH Linux 6.2
Enter this: ls -ls /data/RAIL/rpo402/db/upgrade List the output for the file and look at it's permissions. Make sure the file isn't empty. Make sure the file has permissions to be executed as a shell. chmod +x upgrade_db.ksh Look at the first line of the file, make sure it has a proper header for a shell script. Maybe Korn Shell requires the shell declaration in the header. Check dmesg to see if there are any error messages, perhaps the file system and check inodes.

Categories : Linux

How to move the oldest 10 files in a directory to another directory
var filesToMove = di .GetFiles() .OrderBy(f => f.CreationTime) .Take(10) .ToArray(); foreach (var rgFile in filesToMove) { rgfile.MoveTo(System.IO.Path.Combine(destinationDirectory, rgfile.Name)); }

Categories : C#

Having problems deleting all files in a directory, then the directory itself
Well, I can see a couple of places, where the error could be. First, this line: var item = (((sender as MenuItem).Parent as ContextMenu).Owner as Grid); As you know, when you cast types with as keyword, the result might be null and no exception is thrown. Second, and IMO most important: This line: string[] fileList = appStorage.GetFileNames(directory + "\*"); That won't find anything. You should use "." (star-point-star) instead of "*"(star) in search request. Also, when you work with IsolatedStorage, use using keyword, like: using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { // your code }

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.