w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to rename files in a directory and all subdirectories
Something like: find . -name '*xx*' -print | sed -e 's/^(.*)xx(.*)$/1xx2 1yy2 /g' | xargs -n2 mv Where 'xx' ist the search string for the file names. sed replaces the xx with yy and pipes that to xargs xargs takes now (-n2) two parameters (old and new name) and execute mv with both parms. That is only the start point, try it in a safe environment :-) You have first rename the files ( -type=f ) after that you rename the path ( -type=d ). If you change this order the mv will fail while the directory is renamed while changing the next file name :-) If there are spaces in the file names, you have to use print0 instead of print. But then you also have to change the sed part... I think the rest is your homework :-) Feel free to ask if something will not work at all.

Categories : Unix

How to traverse all the files in a directory and subdirectories as well
rename($file,$new_file) will not work as you did not specify the path rename("$dir_01/$dir_02/$file", $new_file) But also like that any file that matches will be renamed Kernel.txt in the current directory. Is that the expected behavior?

Categories : Perl

prepend all files in a selected directory with a number and a preceding 0
A VBScript solution for renaming PDF files in a given folder by prefixing them with a running number, left-padded with zeroes, could look like this: fldr = "..." Set fso = CreateObject("Scripting.FileSystemObject") i = -1 For Each f In fso.GetFolder(fldr).Files If LCase(fso.GetExtensionName(f)) = "pdf" Then Do i = i + 1 newname = Right("0000" & i, 5) & f.Name Loop While fso.FileExists(fso.BuildPath(f.ParentFolder, newname)) f.Name = newname End If Next

Categories : Shell

Pulling Files and Timestamps from a Directory and Subdirectories
http://docs.python.org/2/library/os.html and http://docs.python.org/2/library/stat.html have you covered. os.walk will give you the recursive directory walking stat will give you file timestamps (atime,ctime,mtime)

Categories : Python

What is better for performance - many files in one directory, or many subdirectories each with one file?
Millions of entries (either files or directories) in one parent directory would be hard to deal with for any filesystem. While modern filesystems use sorting and various tree algorithms for quick search for the needed files, even navigating to the folder with Windows Explorer or Midnight Commander or any other file manager will be complicated as the file manager would have to read contents of the directory. The same applies to file search. So subdirectories are preferred for this. Yet I need to notice that access to particular file would be a bit faster when all files are in one directory than when they are separated into subdirectories at least on NTFS (measured this myself several times with 400K files).

Categories : File

How to hgignore all files of a particular extension except in one directory and its subdirectories?
Let's say you want to exclude the directory named exclude. The following regex would then match all files that end in .tex unless exclude/ comes somewhere before that: ^(?!.*exclude/).*.tex$

Categories : Regex

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 print all files in a directory including subdirectories without recursion in j2me
Make the stack explicit. I've done this in pseudo-code as this sounds a little home-worky! Your current structure is a little like this: public void List(Directory directory) { forevery file in directory if (isDirectory(file)) List(file) else print(file) // recursion uses a stack } Instead you can make the call-stack explicit using your own stack. The recursion becomes replaced with a while loop. public void List(Directory directory) { Stack directories = new Stack(); directories.push(directory); while(!directories.Empty()) { Directory dir = directories.pop(); forevery file in dir if (IsDirectory(file)) directories.push(file) else print(file); } }

Categories : Java

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

Python - Open All Text Files in All Subdirectories Unless Text File Is In Specified Directory
Change your loop to this: for textfile in findfiles(r'C:\Top', '*.txt'): if not textfile.startswith(r'C:\Top\1'): filename = os.path.basename(textfile) print filename

Categories : Python

Redirect all requests to a directory and it's subdirectories to a file inside the directory, using Apache2 server
Place an .htaccess inside project one folder with the following rule: Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase /php/projectone/ RewriteRule ^(view/)?index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . view/index.php [L] And you can repeat that for any other project folders you have. by changing the RewriteBase.

Categories : PHP

Script to prepend all filenames within a directory
without much testing: n=0 # or 1 if you like format="%06d" # format of prefix find . -maxdepth 1 -type f | # only one level, no dirs but also no symlinks etc cut -d/ -f2 | # remove leading ./ sort | # plugin your sorting here while read file do prefix=`printf "%06d" $n` mv "$file" "$prefix$file" # but mv is dangerous! n=$((n+1)) done

Categories : Shell

jquery wrap, append, prepend to parent div
You could try something like this: function checkads() { var $container = $('#container'); if ($container.height() == 0) { $container.parent().wrap($('<div id="notice">ENABLE ADS</div>')); // OR $container.parent().parent().wrap($('<div id="notice">ENABLE ADS</div>')); } } Or change your checkads() function to: function checkads($current) { if ($current.height() == 0) { $current.parent().wrap($('<div id="notice">ENABLE ADS</div>')); } } And call it like: checkads($('#container'); checkads($('#container2'); //etc...

Categories : Javascript

Is it normal to have .svn directory under most if not all of the subdirectories? - svn add issue
This depends on which subversion distribution you're running, prior to version 1.7 there was a .svn directory in every directory in the working copy. Look at Apache Subversion 1.7 Release Notes You could try to upgrade to the new format using svn upgrade

Categories : Svn

Apply directory permissions to all new subdirectories in linux
Most unix command come with a recursive option. In this case: -R, --recursive It seems like you are trying to use this, but you have -Rm. That is not the correct option. I think what you need is: sudo setfacl -R -m g:users:rwX,d:g:users:rwX index/ I typically use chmod instead of setfacl. chmod -R 777 *

Categories : Linux

Create Subdirectories Under Each Directory Using Windows Command Line
for /r %location% %f in ("dir %location% /a:D") do ( You're mixing up the syntax of for /r (recursive processing) with the syntax of for /f (file processing/command substitution). Also, if you're running this in a batch file you need to double the % on the loop variable (%%f). If you want to create the folder structure directly under %location% do this: @echo off setlocal set "location=\READYSHAREUSB_StorageGlobal" md "%location%Archived Tenants" md "%location%Current tenant -" md "%location%Current tenant -Tenancy Sign up Pack" md "%location%Owners" md "%location%OwnersAdvertising Photos" md "%location%OwnersInvoices" md "%location%OwnersQuotes" md "%location%OwnersRoutine Inspections" If you want to create the folder structure under all top-level folders of %location% do this:

Categories : Windows

Ignore only subdirectories within a directory while still including a specific file with tortoisesvn
Do not ignore the Packages directory, itself. You will need this folder to commit your repository config. Right-click the 'Packages' directory, and add it to Subversion. In the 'Add' dialog, select ONLY the Packages directory and the 'repositories.config' file. Right-click the 'Packages' directory again, and this time bring up TortoiseSVN Properties. In the Properties dialog, select New... -> Advanced. In the Advanced dialog, set the property name to 'svn:ignore' and the value to '**'. Done. Commit. The ** ignore setting causes all files and subdirectories to be ignored. However, since repositories.config is committed, it overrides the ignore settings for just this file. The config file will be tracked, and any modifications noted.

Categories : Svn

how to exclude all subdirectories of a given directory in the search path of the find command in unix
Have you tried rsync(1)? It has an option --exclude=PATTERN which might work well here: rsync -avz --exclude=A/a <source> <target> Using rsync you wouldn't need to use find(1)

Categories : Linux

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

Traversing subdirectories & create simillar directory structure to process each file in sub directories
You might try something like this: @echo off for /r "c:adt_folder_root" %%a in (*.adt) do "C:Program FilesABC Amber Advantage Converterabcadv.exe" "%%a" "%%~dpna.csv" 0 The /r switch will traverse the folder structure starting from the folder specified.

Categories : Windows

Unzipping subdirectories and files in C#
if your archive looks like this: archive.zip file.txt someFolder file2.txt then entry.FullName for file2.txt is someFolder/file2.txt so even your code will work normaly if the folder exists. So you can create it. foreach (ZipArchiveEntry entry in archive.Entries) { string fullPath = Path.Combine(extractPath, entry.FullName); if (String.IsNullOrEmpty(entry.Name)) { Directory.CreateDirectory(fullPath); } else { if (!entry.Name.Equals("please dont extract me.txt")) { entry.ExtractToFile(fullPath); } } } or you should better use static ZipFile method if you need to extract all the archive ZipFile.ExtractToDirectory(zipPath, extractPath);

Categories : C#

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

Copy All Files/Subdirectories In a File to Another
Well this is the MSDN example This example demonstrates how to use I/O classes to synchronously copy the contents of a directory to another location. In this example, the user can specify whether to also copy the subdirectories. If the subdirectories are copied, the method in this example recursively copies them by calling itself on each subsequent subdirectory until there are no more to copy. You could also have a look at Asynchronous File I/O Asynchronous operations enable you to perform resource-intensive I/O operations without blocking the main thread. This performance consideration is particularly important in a Windows Store app or desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working.

Categories : C#

Find and gzip files in subdirectories
Since we don't have to recurse, I'd approach it not with find but with globbing and a for loop. If we're in the Calc directory, echo * will give us all the directory names: ~/Docs/Calc$ echo * 2011 2012 2013 It just so happens that we can use a for loop to iterate over these and tar them up in the usual way: for year in *; do tar czf $year.tar.gz $year done If you want the resulting tarballs in the year directories, you could add an mv after the tar command. I'd be hesitant to put the tarball in the directory from outset or tar might start trying to tar its own output into itself.

Categories : Bash

Looping over files in subdirectories of a ZIP archive
I can't reproduce your problem. It works fine in my test case: using (var archive = ZipFile.OpenRead(zipIn)) { foreach (var zipArchiveEntry in archive.Entries) { Console.WriteLine(zipArchiveEntry); } } Console.ReadLine(); Result:

Categories : C#

powershell - concatenate N text files and prepend filename to each line
This one worked for me: ls c: empdata*.txt | foreach-object { $fname=[System.IO.Path]::GetFileName($_); get-content $_ | foreach-object { echo $fname": "$_ >> output.txt}} Just make sure you delete output.txt if you need to run it again or if new data needs to be added. inputs used from above, output.txt: PS C:> cat . empoutput.txt data1.txt: this is the text in data1.txt: data1 file - hello data2.txt: four score and data2.txt: seven years ago

Categories : Powershell

Apache Server Downloads .php Files in Subdirectories
It sounds like you need to look at the action part of your html form. Make sure that the action starts with a / Example <form action="/php_scripts/script_name.php>

Categories : PHP

Find and delete old files excluding some subdirectories
Following command will delete only files older than 1 day. You can exclude the directories as shown in the example below, directories test1 & test2 will be excluded. find /path/ -mtime +60 -type d ( -path ./test1 -o -path ./test2 ) -prune -o -type f -print0 | xargs -0 rm -f Though it would be advisable to see what's going to be deleted using -print find /path/ -mtime +60 -type d ( -path ./test1 -o -path ./test2 ) -prune -o -type f -print

Categories : Shell

Is there any automated [grunt] task to prepend a CDN to CSS/JS files inside your index.html?
I was looking for the same functionality and it seems like this package would do the job: https://github.com/tactivos/grunt-cdn

Categories : Angularjs

script to traverse through directories and subdirectories to list files
if [ -d "$f" ] ^ There needs to be a space between if and [. If you don't have a space, bash thinks you're trying to execute a command named if[. files="/data/*" for f in $files Also know that this won't work. To store a wildcard expansion in a variable like that you need to use an array. The syntax is a bit hairier... files=(/data/*) for f in "${files[@]}" Or you could write the wildcard inline the way you do with the inner loop. That would work fine. for f in "$mydir"/* For what it's worth, you could use find to recurse through all files and sub-directories recursively. find /data/ -type f -print0 | while read -d $'' file; do echo "Processing $file" done -type f matches files only. -print0 combined with -d $'' is a way to be extra careful with file names containin

Categories : Linux

Fetch all files,size,path from directories and subdirectories php
Use glob $folder = dirname( __FILE__ ) ."./images/*"; foreach( glob( './images/*.*' ) as $filename ) { echo $filename; echo $size = filesize($filename); }

Categories : PHP

Gruntjs - watch for changes in a large amount of subdirectories and files
Ok I found the solution. the problem was with the regular expression I used. files: ['template/page/{,*/}*'] should have been: files: ['**/*.*'] to match any file in any sub directory. and: files: ['template/**/*.*'] to match all sub directories and files within the 'template' folder.

Categories : Javascript

Bash finding files in subdirectories and move them into a new folder
Try this command: #!/bin/bash find Dir1 -mindepth 1 -type f -name '*.RAW' | while read -r FILE; do DIRNAME=${FILE%/*} mkdir -p "$DIRNAME/RAW" && mv "$FILE" "$DIRNAME/RAW/" done

Categories : Bash

New at C and working with directories: Trouble opening files within subdirectories
You don't seem to be putting your cwd variable to use. You should be putting that at the start of each filename. Also I like using snprintf instead of strcat for building names. It will limit itself to the buffer size that you pass it, so there is no risk of overflow.

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

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

Get parent directory's parent directory name in java
Have a look at http://developer.android.com/reference/java/io/File.html#getParentFile() Applying this twice will probably get you the right directory. But note that you program might or might not be allowed to go there, based on the settings in the file system and the context your code runs in.

Categories : Java

How to modify this Powershell code so that hyperlinks will also work for HTML files in subdirectories?
Since you need to exchange the basedir in the URL (note: this is significant detail information, you shouldn't omit these things from your questions), something like this should work: $basedir = 'c:inetpubwwwroot' $exp = [regex]::Escape($basedir) $server = 'http://172.16.x.x' Get-ChildItem $basedir -Recurse -Force | select Name, LastWriteTime, @{n="URL";e={$_.FullName -replace $exp, $server -replace '\', '/'}} | ConvertTo-Html -Fragment URL, Name, LastWriteTime ` -PreContent '<html><head><title>Test</title></head><body>' ` -PostContent '</body></html>' | % { $_ -replace '<th>.*</th>','<th>Files</th>' ` -replace '<td>(.*?)</td><td>(.*?)</td><td>(.*?)</t

Categories : HTML

Terminals - Creating Multiple Identical Folders within Subdirectories and Moving Files
I will assume you are using bash, since it is the default shell in OS X. One way to do this uses a for loop over each directory to create the subdirectory and move the file. Wildcards are used to find all of the directories and the file. for DIR in Cars/*/ ; do mkdir "${DIR}Pricing" mv "${DIR}payment*.html" "${DIR}Pricing/" done The first line finds every directory in Cars, and then runs the loop once for each, replacing ${DIR} with the current directory. The second line creates the subdirectory using the substitution. Note the double quotes, which are necessary only if the path could contain spaces. The third line moves any file in the directory whose name starts with "payment" and ends with ".html" to the subdirectory. If you have multiple files which match this, they will all

Categories : Osx

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



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