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

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

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

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

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

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

Move files from one directory to another when request coming from another system
There are some tricks you can do with pollers, such as the FireOnceTrigger I mentioned in this answer. But in this case, probably the simplest solution is, instead of using an inbound adapter, define a <bean/> of type FileReadingMessageSource in your context; get a reference to it in your main() (context.getBean(FileReadingMessagesource.class)). Keep calling receive() and send the message received to the first channel in your flow (or use a <gateway/>. When receive() returns null, exit.

Categories : Spring

How to move all files from one directory to another whose Last modified date was less than today
you can do this by using the find command find . -newermt "2013-09-11 00:00:00" or in your case (for between) find . -newermt "2000-01-01 00:00:00" ! -newermt "2013-09-11 00:00:00"

Categories : Ubuntu

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#

Unable to move mp4 files to another directory in ubuntu using python
When python I/O is given a filename, it assumes that the file is in the current directory, or somewhere on it's path; if it's not in any of those places, it yields an IOError. Therefore, when you are accessing files in directories other than your current directory, it's important to specific the path to that file. In your code, calling shutils.move with f is just supplying the function a file name---the path to that filename has been stripped off. Therefore, your call to shutils.move should look like shutil.move(os.path.join(root, f), dest)

Categories : Python

Batch Command to Move Files from Sub Directories to New Directory
Try using For /F "TOKENS=1 DELIMS=%_TabSpace%" %%B In ('dir %1 /a-d /S /B /OD') DO ( the /s will cause recursion. The downside is that the output of the dir command is then d:pathfile.ext - which may not marry well with your "TOKENS=1 DELIMS=%_TabSpace%". You'd probably need to use "delims=" (ie, no delimiters, hence entire line in token1). You can then retrieve the various parts of the full-filename as %%~dB, %%~pB, %%~nB and %%~xB (the drive, path, naem and extension - and you can combine these parts if you wish by using %%~nxB for name+extension, for instance. Supplemental info - batch commented. @ECHO OFF SETLOCAL :: The above two lines are a traditional batch introduction. :: The first turns `ECHO`ing of the command to the console OFF :: The second makes all changes to the en

Categories : Windows

Use datestring in a filename to create folder directory and move files
I think you will find glob useful and might find some inspiration in this question

Categories : Regex

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 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

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

Batch file to recursively move files to first level directory from deeper subdirectories
try this: @ECHO OFF &SETLOCAL FOR /r "F:" %%a IN (*.rar) DO ( SET "fname=%%~nxa" SET "fpath=%%~fa" FOR /f "tokens=1,2 delims=" %%b IN ("%%~fa") DO SET "targetfolder=%%~b\%%~c" SETLOCAL ENABLEDELAYEDEXPANSION CALL :moveit "!fpath!" "!targetfolder!" "!fname!" ENDLOCAL ) GOTO :eof :moveit SETLOCAL SET "nname=%~3" :loop SET /a fcount+=1 IF EXIST "%~2\%nname%" ( SET "nname=%~n3 (%fcount%)%~x3" GOTO :loop ) ECHO MOVE "%~1" "%~2\%nname%" MOVE "%~1" "%~2\%nname%" ENDLOCAL EXIT /b

Categories : Windows

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

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#

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++

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

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

Recursively adding .org files in a top-level directory for org-agenda-files takes a long time
I also tried "recursive directory listing" at Emacs startup. It simply is way to loooong to be usable. So, try to stick with a limited number of "root" directories where you put your agenda files. Even better is sticking with "~/org", and possibly a few subdirs like "work" and "personal", and that's it. You can put there your agenda files, and have links Inside them to your real project root dirs. I know, this is not optimal, but I don't have anything better right now.

Categories : Emacs

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

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

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 move multiple files with whitespace on linux
There's probably 400 ways to do this.. using find is likely the more efficient way, but: You can use a for loop: for i in `ls`; do mv $i dir/newdir/; done Or a while loop with the file you created in your step 1: ls -la|grep -e "May"|awk "{print $9, $10}" > some.files; cat some.files | while read mFILE; do mv $mFILE dir/newdir; done Or with find (where +30 is greater than X days): find ./ -mtime +30 -exec mv dir/newdir {} ; OR, if you want to use awk and xargs: ls -la|grep -e "May"|awk "{print $9, $10}" | xargs mv dir/newdir/

Categories : Linux

Select multiple files (different files from different directory) with 1 input type file element.
Using more than one <input type="file" /> element for your form is the best you can do. It's not possible to select multiple files from different directories in a single upload dialog.

Categories : HTML

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#

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

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 get the list of files created during a specific period of time in a directory?
Copying should not "modify" the creation time; since the destination file was actually only created at copying time, isn't it only logical that the creation time of the copied file is the time when the copying occured? The file creation time is however not really available under linux anyway (see the question you linked yourself How to get file creation time in linux using c++, or http://superuser.com/questions/437663/whats-an-elegant-way-to-copy-the-creation-and-modification-dates-of-a-file-to-a). So you'll have to encode that in some other way anyway. Encoding it in the filename as you suggest sounds like a reasonable way!

Categories : C++

read multiple files with php from directory
Try this: <?php foreach (glob("myfiles/*.html") as $file) { $file_handle = fopen($file, "r"); while (!feof($file_handle)) { $line = fgets($file_handle); echo $line; } fclose($file_handle); } ?>

Categories : PHP

decrypt multiple OpenPGP files in a directory
gpg can decrypt multiple files so you shouldn't need to write a loop. Try the following. You will need to enter your password once. gpg --passphrase-fd 0 --decrypt-files *.gpg

Categories : Bash

Reading multiple csv files from a directory in python
This is weird: avg_rel_track_nan=avg_rel_track_nan(avg_rel_track) You probably meant: avg_rel_track_nan=averaged_rel_track_nan(avg_rel_track) I can't tell for sure what is happening because a lot of your code depends on some other code but you are assigning the result of a (supposedly) function call to the name of this function. I'm guessing that's not what you meant to do.

Categories : Python

NullPointerException while reading multiple files from a directory
folder.listFiles() returns null, when folder isn't a directory (which it is in this case) or when an IO error occurs. Is it possible that the web server doesn't have the correct rights to access some folders? Or they are not reachable (they are connected via a network). Add a nullcheck to folder.listFiles() and print out for which folders it returns null. This should help you to determine why it is happening. If you can't find the cause, please add the folders for which it is happening to the question.

Categories : Java

Randomly Generate Multiple Files From Directory with PHP
Remove randomly selected image from $images before you select another. loop for 5 images <?php // get all files $imagesDir = 'uploads/'; $images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE); $imagesCount = count($images); for($i = 0 ; $i < $imagesCount ; $i++) { // select image $randomIndex = array_rand($images); // select image index $file_title = $randomImage = $images[$randomIndex]; // use selected image unset($images[$randomIndex]); // remove selected image // print_r($images); // you can see what left in $images // show image ?> <article class="item thumb"> <h2><?php echo $file_title;?></h2> <a href="<?php echo $randomImage ?>"><img src="<?php echo $randomImage ?>

Categories : PHP

403 error just for directory, and not files in the directory
Assuming you are using Apache, you should disable directory browsing in the config. Find your httpd.conf (likely at /etc/apache/httpd.conf), and remove 'Indexes' from a line that will look like this: Options Includes Indexes FollowSymLinks MultiViews so that it looks like this: Options Includes FollowSymLinks MultiViews Then restart Apache. BTW, that kind of question is better asked here instead: http://webmasters.stackexchange.com/

Categories : Image

How do i copy files from one directory to another directory?
You are doing it the right way.. See example from microsoft http://msdn.microsoft.com/en-us/library/bb762914.aspx another solution might be to call the xcopy command ...

Categories : C#



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