w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Delete all files from a directory except for folder and it's contents
The problem is the way in which the recursive function calls are done: the main function private static void WalkDirectory(DirectoryInfo directory) deletes all files and is called every time (even while analysing a subdirectory). Here you have a fix to make this code work as you wish: private static void WalkDirectory(DirectoryInfo directory) { if (directory.Name.ToLower() != "data") { // Scan all files in the current path foreach (FileInfo file in directory.GetFiles()) { file.Attributes &= ~FileAttributes.ReadOnly; var name = file.Name; name = name.ToLower(); if (name != "test.txt") { file.Delete(); } } DirectoryInfo[] subDire

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

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

According to files names of a file, duplicate files into anther directory
You need to turn the first file into a set (for fast membership testing). You are also using os.walk, which gives you three pieces of information, the path to the directory, a list of subdirectories and a list of the files in that directory: import sys import shutil,errno import os srcDir = 'Root' dstDir = 'De' with open('file.txt','r') as f: read_filenames = {fname.strip() for fname in f} # set comprehension for root, directories, files in os.walk(srcDir): for filename in read_filenames.intersection(files): shutil.move(os.path.join(root, filename), dstDir) The .intersection() call returns all elements in the read_filenames set that are also in the files list. Note that I tell shutil.move() the full path of the file to move to dstDir, using os.path.join() based on th

Categories : Python

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

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#

Getting name(s) of FOLDER containing a specific SUBSTRING from the C:Temp directory in C#
You don't want to have the message box inside the loop. string name = txtNameSubstring.Text; string[] allFiles = System.IO.Directory.GetFiles("C:\Temp");//Change path to yours foreach (string file in allFiles) { if (file.Contains(name)) { cblFolderSelect.Items.Add(file); // MessageBox.Show("Match Found : " + file); } } if(cblFolderSelect.Items.Count==0) { MessageBox.Show("No files found"); } (Assuming cblFolderSelect was empty before this code runs) As you currently have it, you're deciding whether to show the message box for each file that you examine. So if the first file doesn't match, you'll be told "No files found" even though the next file might match. (I've also changed the Add to add the individual file that matches, not all of the files (for which one

Categories : C#

read all files from a folder or directory
If implementing under windows just read use dirent.h http://pubs.opengroup.org/onlinepubs/007908799/xsh/dirent.h.html You're gonna want to check the readdir function and check the example. Use it to get the name of the files than apply the rest of the process for each file,

Categories : C

How to add a file thats copied from one directory to a folder in another directory thats incremented
I would recommend using time stamps rather than sequential numbering. Also here is everything in one command and it is user independent. @xcopy "%LocalAppData%GoogleChromeUser DataDefaultookmarks*" "%UserProfile%DesktopBackup of Bookmarks\%Date:~10,4%-%Date:~4,2%-%Date:~7,2%" /I /Y This will copy both the bookmarks and bookmarks.bak file to a time-stamped folder inside the Backup of Bookmarks folder.

Categories : Batch File

How to properly delete files in directory
You can't call php from javascript like that, php will always execute. The thing you want is Ajax. file.php $files = glob('d:/pics/*'); // get all file names foreach($files as $file){ // iterate files if(is_file($file)) unlink($file); // delete file } and ajax in javascript, if you use jQuery it will be something like function checkMe() { if (confirm("Are you sure")) { $.get('file.php', function() { //ignore }); } } or you can put php in index.php file and check: if (isset($_GET['main']) && $_GET['main'] == 'add-doc') { $files = glob('d:/pics/*'); // get all file names foreach($files as $file){ // iterate files if(is_file($file)) unlink($file); // delete file } } and in javascript put only c

Categories : PHP

Moving all files in a folder to a new child directory
This should do what you want. Create a variable named $myDir first that has the full path of your desired parent directory. New-Item $myDir"TestDirectory" -type directory $files = Get-ChildItem $myDir*.* Move-Item $files $myDir"TestDirectory" Using a single * will also select child directories, which may have been part of your problem if you had inadvertently selected the new directory to be moved and also as the destination in the same action. *.* should match for files. Feel free to condense the statements once you're okay with what they're doing.

Categories : Windows

how to watch changes in whole directory/folder containing many sass files
You can create one sass file which includes the rest of the files, and then just watch this file. Alternately, look into Grunt and the very good grunt-contrib-compass plugin

Categories : CSS

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

Delete files from directory that are not in Excel spreadsheet
I would use Dir() to list all the files in the directory into a second column of Excel use For Each to examine each cell in this new column of file names within the For..Each use Excel's MATCH function to check if the file exists in the existing column use Kill to delete the files Delete these two columns when complete. I might store a value of "DELETE" in a third column and do the deletions separately afterwards. (Or, more usefully, just copy the name of the file to delete to this third column.) I am reluctant to provide code though until you have made an attempt yourself. Added Actually, I would probably use COUNTIF() in the third column and use this as the basis to perform file deletions; but there are always a number of approaches to take ;)

Categories : Excel

ant task to delete files and directory that start with the same name
Use a fileset to select files with a pattern, a dirset to select directories with a pattern. This should do the job: <delete> <dirset dir="${basedir}" includes="test*" /> <fileset dir="${basedir}" includes="test*" /> </delete>

Categories : Ant

Shell Script to copy all files in a directory to a specified folder
I guess this what you are looking for : #!/bin/bash dir=$(cat a.txt) for i in $(ls -l|grep -v "^[dt]"|awk '{print $9}') do cp $i $dir/$i"_"$(date +%Y%m%d%H%M%S) done I assumed that a.txt contains only the name of the destination directory. If there are other entries, you should add some filter to the first statement(using grep or awk). NB: I used full time stamp(YYYYMMDDHHmmss) instead of your YYYYMMDDmmss as it doesn't seem logical.

Categories : Shell

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

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#

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

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

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

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

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

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

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

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

copy all the files that end with specific name to another directory
Use rename('images/06/*abc.jpg', 'images/07/*abc.jpg'); and if you want just the Thumbnails: rename('images/06/*_abc.jpg', 'images/07/*_abc.jpg'); btw if you want all files that begin with abc use abc*.jpg

Categories : PHP

Remove or delete resource files from target directory using pom file
mvn clean will remove the target directory (and therefore all the files in it). If you want to remove only certain files from the target directory, a combination of: excludeDefaultDirectories to stop it from deleting the whole directory, and filesets to tell it what to delete ref: http://maven.apache.org/plugins/maven-clean-plugin/clean-mojo.html

Categories : Maven

Batch file to delete subfolders in directory if all files is older than 3 days
This uses a VBS script to calculate the date 3 days ago, and then checks if any files are younger than that, using xcopy, and if no files are younger than 3 days then it should remove the "C:UsersMahmo03SShabanAnsys" folder and subdirectories. 3 days is a date calculation and not exactly 72 hours. It's not tested. @echo off call :date today -3 echo mm-dd-yyyy 3 days ago was: %day% xcopy "C:UsersMahmo03SShabanAnsys*.*" "%temp%" /l /s /d:%day% |find ":" >nul if %errorlevel% EQU 1 rd /s /q "C:UsersMahmo03SShabanAnsys" goto :EOF :date set date1=%1 set qty=%2 set separator=%~3 if /i "%date1%" EQU "TODAY" (set date1=now) else (set date1="%date1%") echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%) echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_ echo>>"%temp%\%~n0.vb

Categories : Windows

Creating a script to delete old log files, that allows me to pass directory/age/regex arguments
If you insist on using Perl, look into File::Find & friends. Though if you're on a *nix box you should probably be aware of find(1) for tasks this common. try: find /release/logs -name test.log-* -mtime +7 -delete If you want to test it out 1st, leave off the -delete flag & it will just print a list of the files it would have otherwise deleted.

Categories : Perl

Batch Script to Delete Files with Unique Root Stem in Directory
The way i'd go about this is as follows, i will explain the logic and i'll leave you to do the coding. You will parse all the file names into variables, while increasing each time. Then you will set a limit to the number of loops to go through. Then you will search the first 13 characters of the file name and if the number of lines is equal to 1 then delete it. After you will increase the variable by 1 and go through the loop, at the end of each loop it will check if it has reached the limit aka the number of files in the directory, if it has reached the limit, end the loop, otherwise continue. hah, i finally decided to do it after a guy decided to use my idea i described into actual code, anyway this is way shorter and a lot faster than his, tested+verified to work: @echo off & setl

Categories : Batch File

ftp connect, processing files from a specific directory
C++Builder ships with Indy, which has a TIdFTP client component. Simply have it Connect() to the desired FTP server, ChangeDir() to the desired folder if needed, List() the current files if needed, Get() the desired file(s) to your local machine, process and modify them as needed, and then Put() them back into the remote folder.

Categories : C++

Uploading Files in a specific directory on server
This has nothing to do with tomcat, it is handled by vaadin. Look the the book of vaadin for a example. https://vaadin.com/de/book/vaadin7/-/page/components.upload.html

Categories : Tomcat

How to get files from a directory on specific condition one file must come after another
I have 2 things to suggest you: 1. Change equals method with matches method. Matches method is the best method to compare Strings. 2. Try to separate the moment in which you do batchUpload from that in which you do validateData. Maybe you jump some files. For example the algorithm finds first the "expected-table.data" file and then the "test.data" file. In this case it doesn't validate the file. I hope my answer is usefull and I hope I have understood your problem : )

Categories : Java

Ignore a directory except specific files in a subdirectory in Git
Allowing everything under install after ignoring everything else (*) has the form * !/dev !/dev/host !/dev/host/mail !/dev/host/mail/htdocs !/dev/host/mail/htdocs/install !/dev/host/mail/htdocs/install/* But this also allows stray files at higher levels of the tree. That means adding the additional ignore rules from your question. The short answer is what you have is necessary. It is an odd repository structure, so git does not optimize for it.

Categories : GIT

List of specific files in a directory using `dir` command in matlab
You can use regular expressions in MATLAB to filter out what you want. It's not perfect, but gives decent results. The following code pulls out the 03.dat, 04.dat, 05.dat, 06.dat files: listing = dir('*.dat'); pattern = '0[3-6].dat'; % this is kind of crude, but works: use regexp then pull out all the % non-matching ones with a call to isempty(...) notMatching = cellfun(@isempty, regexp({listing.name}, pattern)) % Pull out the the ones that match: betterListing = listing(~notMatching)

Categories : Matlab

Maven: including non-java files from more specific directory
Change it to, may be there is no more sub dir to look into <resources> <resource> <directory>src/main/java/com/oppballi/kanake</directory> <includes> <include>*.txt</include> </includes> </resource> </resources>

Categories : Java



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