w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
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

BASH | Adding elements in all files of a specific directory bash
This can make it: for file in /your/dir/* do echo "<end>" >> "$file" done In case you have some dirs inside, you may get the error bash: XX: Is a directory. To avoid seeing them, you can add 2>/dev/null to the end of the echo command: echo "<end>" >> "$file" 2>/dev/null Or even better (thanks Barmar), check if they are files: [ -f "$file" ] && echo "<end>" >> "$file" Which is a short way of doing an if-condition: if [ -f "$file" ]; then echo "<end>" >> "$file" fi

Categories : Bash

Bash script to analyze directory and print directory summary
in your code use the following : @where ls -ld is written getting directories ls -latr | sed -n '/^d/p' zdirlst | grep -v "." getting files : ls -latr | sed -n '/^-/p' zdirlst | grep -v "." add wc -l to get count and display as per reqd ... hope this helps !!

Categories : Bash

git move file and directory into a sub-directory along with commit history
To add to bmargulies's comment, the complete sequence is: mkdir -p x/p/q # make sure the parent directories exist first git mv x/* x/p/q # move folder, with history preserved git commit -m "changed the foldername x into x/p/q" Try it first to see a preview of the move: git mv -n x/* x/p/q Wolfgang comments: If you're using bash, you can avoid the issue of trying to move a folder into itself by using an extended glob like so (using the shopt built-in): shopt -s extglob; git mv !(folder) folder

Categories : GIT

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

Bash - How can I locate a specific file in a directory within a loop?
try export d="`pwd`" find ./A/*|while read file do echo "$file" if [ -f "$d/B/${file}_extendedname1.jpeg" ] then echo "$d/B/${file}_extendedname1.jpeg" found fi done

Categories : Bash

Directory.Delete(path, true) throws IOException "The directory is not empty"
It appears that info.EnumerateFiles was the issue. I got that idea from this answer. I switched that to info.GetFiles and I was then able to delete the directory after.

Categories : C#

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#

Bash is symlinking to working directory instead of specified directory
Short answer Your quoting is wrong. ln -sn -- "$FILE_PATH" "$TEST_DIR/$FILE_NAME" Longer answer This does not really relate to your problem, but I want to point it out. Do not use "" inside [[ ]], so instead of this if [[ -z "$1" ]]; then use this if [[ -z $1 ]]; then What is the point of making sure that directory does not have a trailing slash? It has no effect! /usr/bin/ is the same directory as /usr/bin or /usr////bin or /usr////////bin////// Do not check if a directory exists when creating directories. Use -p option! Example: mkdir -p "$HOME/.config/old_dotfiles" Instead of if [ $DECISION == "N" -o $DECISION == "n" ]; use if [[ ${DECISION^^} == N]]; I have another great answer about bash code style HERE. Please check it out! Also read the comments, since I was explaining there

Categories : Linux

How to delete files from directory on specific time, daily?
The script you posted deletes .txt files in the given folder if they are older than a day but the problem is that this test only happens once - when you run the script. What you need to do is run this script periodically. If you are running this on Linux you should probably add a cron job that executes this script periodically, say once an hour or once daily. If you're running this on Windows, there is a task schedule that you could use to accomplish the same thing.

Categories : PHP

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#

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

rsync recursively and exclude content of specific directory, not the directory
In recent versions of rsync, you can use the -F option and put a file ".rsync-filter" in the directory src, containing: - dir1/*** That seemed to work for me. I'm assuming that your hierarchy above is all under "src/".

Categories : Linux

phing - delete directory contents without directory itself
I have just tried it myself and the same code would not delete the include folder. Only way to make it do so was to set the includeemptydirs to true. Maybe it's a version problem, but still, I would try calling it like this: <delete> <fileset dir="folder" casesensitive="false" includeemptydirs="false"> <exclude name="excluded.php"/> </fileset> </delete>

Categories : PHP

Deletion of a directory with System.IO.Directory.Delete
Use the overload that accepts a boolean as the second parameter and pass true. That will recursively delete all files and directories in the directory. See http://msdn.microsoft.com/en-us/library/fxeahc5f.aspx Directory.Delete Method (String, Boolean): public static void Delete( string path, bool recursive )

Categories : C#

Find file within directory and delete the directory its in
%~dp1 can be used to convert a file param to a drive and path. Quote the output as it doesn't convert to 'safe' path names. SS64 is a great resource for learning command scripting.

Categories : Batch File

Bash script that move files from one directory with lots of files to a month folder
something like this? DEBUG=echo cd ${directory_with_files} for file in * ; do dest=$(stat -c %y "$file" | head -c 7) mkdir -p $dest ${DEBUG} mv -v "$file" $dest/$(echo "$file" | sed -e 's/.* (.*)/1/') done DISCLAIMER: test this in a safe copy of your files. I won't be responsible for any lost of data ;-)

Categories : Bash

Remove entire image if image source is within a specific directory
An example using the DOM: $doc = new DOMDocument(); @$doc->loadHTML($yourHTML); foreach($doc->getElementsByTagName('img') as $imgNode) { if (strpos('/smilies/', $imgNode->getAttribute('src'))) $imgNode->parentNode->removeChild($imgNode); } $yourHTML = $doc->saveHTML();

Categories : PHP

upload image to root directory from sub directory php
As far as I know there is no problem with accessing other directories, as long as your user has sufficient file access permissions. Maybe try using a full file path $_SERVER["SCRIPT_FILENAME"] and save your file with an absolute path?

Categories : PHP

Imagick or header issue in wordpress and save that image to specific directory
You should use an image tag with the src tags containing the direct or base64 version of the image. First example would be direct: echo '<img src="http://localhost/wordpress3.5/'.$_SESSION['imgname'].'">'; Second would be using base64 with the data URI scheme, PHP Example: echo '<img src="data:image/png;base64,'.base64_encode($combined).'">'; I would recommend the first method, simply because it looks like a product display, the images are most likely public and hotlinking can be busted if you choose. In both examples, since the image is inline, you wouldn't need to set the content-type to an image. You should also place the correct mime type within the second version, either image/png, image/jpeg or others depending on the image. Edit: To extend this: $combined cont

Categories : PHP

How to access a file in a directory from other directory, when both are in same parent directory with HTML
if dir1 and dir2 are in the same parent directory then this is how you access 2.html from 1.html: <a href="../dir2/2.html">link to 2.html</a> hope it helped :)

Categories : HTML

Why is "local delete, incoming delete upon update" of a directory a conflict?
I started digging in to this, and I think it may come from the fact that SVN is not entirely sure whether the delete is a simple delete, or actually a move (a copy, and a delete). From the documentation, it states: Because a move in Subversion is implemented as a copy operation followed by a delete operation, and these two operations cannot be easily related to one another during an update, all Subversion can warn you about is an incoming delete operation on a locally modified file. This delete operation may be part of a move, or it could be a genuine delete operation. So it sounds like to be safe, SVN warns you instead that you should update. Of course, it could ignore the delete "conflict", and simply copy over the newly moved folder, but I think some metadata may perhaps be los

Categories : Svn

How can move file from one directory to another
If you want to get a List<String> with each element the canonical path of the corresponding file, this is how: List<String> list = new ArrayList<String>(); for (File file : finalListNames) list.add(file.getCanonicalPath()); If that's not what you want, please clarify.

Categories : Java

how to move a file to other directory in javascript?
Tried this code, working perfectly : function moveFile(){ var object = new ActiveXObject("Scripting.FileSystemObject"); var file = object.GetFile("C:\wamp\www\phptest.php"); file.Move("C:\wamp\"); document.write("File is moved successfully"); } In your code, issue seems to be in file path "./Docus/". Try to put absolute path and then check.

Categories : Javascript

Move project directory from to a new machine (git)
Your pushing url still points to bitbucket, even tough the repository doesn't exist on bitbucket anymore (as you migrated it from bitbucket to somewhere else). To change that url type: git remote set-url origin ssh://your_new_url If your pushing and fetching urls are not the same, you need to insert --push after set-url OR If you didnt migrate the repository from one online repo to another, but instead migrated from one client to another (clients not servers!) then you may have a problem with your ssh key and/or connectivity. Check that you can connect to bitbucket (just visit their webpage). Also check that your ssh key setup works. Can the new client login to bitbucket with the ssh key it uses? Also, as Mike Ver posted, you may have this problem: Git error: conq: repository does no

Categories : GIT

Create a directory and move files into it
I'm not sure what's going on with your first line of code Then /^screen shots are placed in the folder "(.*)"$/ do |folder_name| as it's not Ruby code, but I've made it work with a notional line from a file. The Pathname class allows things like destination.exist? instead of File.exist?(destination). It also lets you build composite paths with + and provides the children method. The FileUtils module provides the move facility. Note that Ruby allows forward slashes to be used in Windows paths, and it is usually easier to use them instead of having to escape backslashes everywhere. I've also added a hyphen between the date and the time in the directory name, as otherwise it's pretty much unreadable. require 'pathname' require 'fileutils' source = Pathname.new('C:/my/source') line =

Categories : Ruby

Bash No such file or directory
Remove the extra $ before diffv assignment. Use: diffv=$(which diff) And: diffv=$MY_DIFF With $ you get: <diffv value, empty>=<MY_DIFF value, or which diff> =/opt/gnu/bin/diff

Categories : Bash

move the reference to working directory using libgit2sharp
What I am trying to do here, however, is to change the reference to the working directory for the repo AFTER it is created by Repository::Init(). Repository.Init() puts a folder under source control by creating a new repository on the filesystem. It returns an instance of the created repository. The constructor of the Repository type gives you acces to an existing repository. This constructor accepts an optional RepositoryOptions parameter to override some options. In order to fulfill your request I'd go with something like this var path ="D:path oyour epo"; using (var repo = Repository.Init(path) { // Do nothing here } var newWorkdir ="D:path oyourotherworkingdirectory"; var options = new RepositoryOptions { WorkingDirectoryPath = newWorkdir }; using (var repo = new Reposito

Categories : Visual C++

Fail to move mysql's data directory
It seems you moved the datadir to your home directory. I think that when you start mysqld via your service manager (in your case systemd) it will be started as an unprivileged user (most likely mysql). I strongly doubt that this user has privileges to access the homedir of the user elderry. So the solution would either be moving your datadir to a more suitable location like /var/lib/mysql and chown this directory to the user under which mysql runs. Or that you give the mysql user privileges that he can acces the homedir of elderry.

Categories : Mysql

PHP script to move a directory from one Linux server to another?
there are many ways to do this but the easiest seems to be to send your cmd with php's exec or passthru function. http://php.net/manual/en/function.exec.php http://www.php.net/manual/en/function.passthru.php Warning When allowing user-supplied data to be passed to this function, use escapeshellarg() or escapeshellcmd() to ensure that users cannot trick the system into executing arbitrary commands.

Categories : PHP

How do I move a Wordpress page up a directory level?
use rewrite rules. e.g. RewriteRule ^videos/(.*)$ /blog/videos/$1 [L] http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

Categories : Wordpress

move up and down in directory structure to access file
Since currentDir is a DirectoryInfo currentDir.Parent gives you the DirectoryInfo of the parent directory including the full-path and all other informations of DirectoryInfo. You have to use it's FullName property: string fullPath = parent.FullName; If you want to find the file: FileInfo[] files = currentDir.Parent.Parent.GetFiles("FileName.txt", System.IO.SearchOption.TopDirectoryOnly);

Categories : C#

How do I get the absolute directory of a file in bash?
To get the full path use: readlink -f relative/path/to/file To get the directory of a file: dirname relative/path/to/file You can also combine the two: dirname $(readlink -f relative/path/to/file) If readlink -f is not available on your system you can use this: function myreadlink() { ( cd $(dirname $1) # or cd ${1%/*} echo $PWD/$(basename $1) # or echo $PWD/${1##*/} ) } Note that if you only need to move to a directory of a file specified as a relative path, you don't need to know the absolute path, a relative path is perfectly legal, so just use: cd $(dirname relative/path/to/file) if you wish to go back (while the script is running) to the original path, use pushd instead of cd, and popd when you are done.

Categories : Linux

How do I change the directory in Git Bash with Git for Windows?
You will need to use quotes in your directory name, or the short version of the filename. You can find the short version of the file name by issuing the command: dir /x If I remember correctly. I do not have a windows machine. It is a version of bash shell though, so you should be able to simply quote it. (And the dir /x may or may not work.)

Categories : Linux

BASH if directory contains files or doesn't
find could be helpful here: if [[ $(find ${dir} -type f | wc -l) -gt 0 ]]; then echo "ok"; fi UPD: what is -gt? man bash -> / -gt/: arg1 OP arg2 OP is one of -eq, -ne, -lt, -le, -gt, or -ge. These arithmetic binary operators return true if arg1 is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to arg2, respectively. Arg1 and arg2 may be positive or negative integers. So, -gt is "greater than" boolean function.

Categories : Bash

Run bash script as if I it was executed from a different directory
you could change the working directory before you execute each script, or redirect the output to the directory you want: cd /experiments/exp1/ sh /experiments/exp1/script1.sh >report1.txt or sh /experiments/exp1/script1.sh > /experiments/exp1/report1.txt

Categories : Linux

bash:python3.3 no such file or directory
It seems like bash is caching the previous location of python3.3 somewhere. Try closing your shell and logging in once again - that should wipe the cache and allow bash to pick up the proper location of python3.3.

Categories : Linux

bash: is possible to prefix a command with a directory?
Using the auxiliary shell variable is not that ugly, and would be fine to use. Another option is to write a simple wrapper that will search the PATH for you. For example, call this script path: #!/bin/bash IFS=: for i in $PATH; do cmd="$i/${1?No command specified}" if test -x $cmd; then shift IFS=$' ' exec "$cmd" "$@" fi done echo Command not found: "$1" >&2 exit 1 and invoke it from the crontab as: path foomatic/featurizer

Categories : Bash

Bash - Printing Directory Files
Here is a solution: #!/bin/bash target="/home/personal/scripts/07_22_13/ford/$1" let count=0 for f in "$target"/* do echo $(basename $f) let count=count+1 done echo "" echo "Count: $count" Solution 2 If you don't want to deal with parsing the path to get just the file names, another solution is to cd into the directory in question, do your business, and cd back to where you were: #!/bin/bash target="/home/personal/scripts/07_22_13/ford/$1" pushd "$target" > /dev/null let count=0 for f in * do echo $f let count=count+1 done popd echo "" echo "Count: $count" The pushd and popd commands will switch to a directory, then return.

Categories : Linux

How can I reliably move files (asynchronously) from a directory as they're being created?
First of all you need to 'detect' the exceptions thrown in process of asynchronous execution. This can be done by something like this: try { await sourceStream.CopyToAsync(destStream); } catch (Exception copyException) { } Once an exception is detected and properly handled i.e. you decide that one particular exception is a reason for a retry, you will have to maintain your own queue of copy targets (and destinations) that are due for a retry. Then you will have to organize a new entry point that would lead to a retry itself. Such an entry point could be triggered by a timer or a next event from the file system monitor you use (which I would not recommend). You will also have to implement a detection for an overflow of your que

Categories : C#



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