Rails server command generates another folder in project's folder with default folders and files |
This is because you are using rails 2 gem version, you can check by rails
-v. As well you can see, there is no app/assets folder. there are only
public/javascripts etc rails2 style directories
Try to install rails 3 by
gem install rails --version '>3.0.0'
|
Iterate over 2 files in each folder and compare them |
You can indeed use os.walk(), since that already separates the directories
from the files. You only need the directories it returns, because that's
where you're looking for your 2 specific files.
You could also use os.listdir() but that returns directories as well files
in the same list, so you would have to check for directories yourself.
Either way, once you have the directories, you iterate over them (for
subdir in dirnames) and join the various path components you have: The
dirpath, the subdir name that you got from iterating over the list and your
filename.
Assuming there are also some directories that don't have the specific 2
files, it's a good idea to wrap the open() calls in a try..except block and
thus ignore the directories where one of the files (or both of them)
doesn't exi
|
Iterate over a very large number of files in a folder |
By default os.walk walk the directory tree bottom-up. If you have a deep
tree with many leafs, I guess this could leave to performances penalties --
or at least for an increased "statup" time, since walk has to read lots of
data before processing the first file.
All of this being speculative, have you tried to force a topdown
explorations:
for root, subFolders, files in os.walk(rootdir, topdown=True):
...
EDIT:
As the files appear to be in a flat directory, maybe glob.iglob could leave
to better performance by returning an iterator (whereas other method like
os.walk, os.listdir or glob.glob build first the list of all files). Could
you try something like that:
import glob
# ...
for infile in glob.iglob( os.path.join(rootdir, '*.*') ):
# ...
|
XCOPY files in batch to another folder but with structure of folders |
Ah, finally found it. Putting an asterisk * behind the filename will do the
trick. So, for any of you with the same problem:
XCOPY "abcdef01.jpg" "D:
ewphotosabcdef01.jpg*"
This does the trick.
|
How to recursively retrieve files from folders returning file name and its Folder name |
You may want to use folderFullPath.lastIndexOf(File.separator) in order to
find the index of the character before the folder name and then use
substring to extract the folder name from the full-path.
|
Rename files within folders to folder names while retaining extensions |
Here's something simple:
find * -type f -maxdepth 1 | while read file
do
dirname="$(dirname "$file")"
new_name="${dirname##*/}"
file_ext=${file##*.}
if [ -n "$file_ext" -a -n "$dirname" -a -n "$new_name" ]
then
echo "mv '$file' '$dirname/$new_name.$file_ext'"
fi
done
The find * says to run find on all items in the current directory. The
-type f says you only are interested in files, and -maxdepth 1 limits the
depth of the search to the immediate directory.
The ${file##*.} is using a pattern match. The ## says the largest left hand
match to *. which is basically pulling everything off to the file
extension.
The file_dir="$(dirname "$file")" gets the directory name.
Note quotes everywhere! You have to be careful about white spaces.
By the way, I echo i
|
Hadoop HDFS Copy Files from multiple folders to one destination folder |
There is DistCp which is an map-reduce job which copies files from one or
multiple source folders to one target folder in an parallel manner.
However, its not merging files.
But maybe you could use filecrush to do that! (let me know how this goes!)
|
Run a batch file that would delete files in a folder (and its sub folders) that are older then 30 days |
I did some copy and paste for you from here:
forfiles -p "C:whatever" -s -m *.* /D -30 /C "cmd /c del @path"
See forfile documentation for more details.
|
Move multiple files from multiple folders to one folder |
How far have to got with this ? Have you managed to get them moving from
one folder to another yet ? Is it an issue with the sub-folders ? I had a
similar issue before and i found this answer really helped me : move files
between folders
|
Batch: Create a list of folders and then copy multiple files/folders into all of them |
Try this:
@echo off &setlocal
cd /d "RootFolder=X:folder omy data"
for /d %%a in (*) do xcopy "_TEMPLATE" "%%~fa" /sihrky
For xcopy options see xcopy /?, to test the command without writing add
option /l.
|
How to stop threads of following type in Java used for watching folders for files using WatchService for folders by using jToggleButton |
There is a Thread.stop() method, but is has been deprecated, because it's
unsafe.
Instead of using the deprecated method(s), you can modify some variable to
indicate that the target thread should stop running.
|
MATLAB: Opening and Editing Files nested in folders in folders |
Check out subdir! On the file exchange, its an awesome function that can
return all folders and all files in expansive subfolders, and you can
filter file names by extension and whatnot.
http://www.mathworks.com/matlabcentral/fileexchange/15859-subdir-a-recursive-file-search
|
Iterate over folders in JAR file directly |
You cannot create File objects from arbitrary URLs and use the usual
filesystem traversal methods. Now, I'm not sure if launch4j does make any
difference, but as for iterating over the contents of plain JAR file, you
can use the official API:
JarURLConnection connection = (JarURLConnection) url.openConnection();
JarFile file = connection.getJarFile();
Enumeration<JarEntry> entries = file.entries();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
if (e.getName().startsWith("com")) {
// ...
}
}
Above snippet lists all the entries in the JAR file referenced by url, i.e.
files and directories.
|
Moving files from one folder to a hot folder BUT only move one at a time when the hot folder is empty |
Pretty sure this should do what you want in vbscript:
Set objFS = CreateObject("Scripting.FileSystemObject")
set objFolderA = objFS.GetFolder("c:Folder A")
set objFolderB = objFS.GetFolder("c:Folder B")
For each objFile in objFolderA.Files
Do While True
If objFolderB.Files.Count = 0 Then
objFS.MoveFile objFile.Path, ojbFolderB.Path & ""
Exit Do
End If
Loop
Next
|
Trying to "iterate" a folder |
There is a very helpful method in .NET to do this Directory.EnumerateFiles:
For Each fileName As String In Directory.EnumerateFiles(myDirectory)
' Add your code
Next
You have to import the System.IO namespace to use the Directory class:
Imports System.IO
|
Copy folders and exclude folder |
I'd suggest splitting the problem into 4 subs. Firstly two subs to allow
users to select a folder they desire for source and destination. The a
button click event that starts the copying and finally a sub that actually
handles the copying.
Try this on for size:
Dim CopyFromPath As String
Dim CopyToPath As String
Private Sub TextBox1_MouseClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.MouseClick
Dim fldbroser1 As New FolderBrowserDialog
fldbroser1.RootFolder = Environment.SpecialFolder.MyMusic
fldbroser1.ShowDialog()
CopyFromPath = fldbroser1.SelectedPath
End Sub
Private Sub TextBox2_MouseClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox2.MouseClick
Dim fldbroser1 As New FolderBrowserDialog
f
|
Items_ItemAdd listener for folder and it's sub folders in Outlook |
You need to install the event sink on each folder's Items collection.
To make sure all Items objects are alive while your app runs, store Items
in a list (e.g. List<Outlook.Items>)
|
delete all the folders inside a parent folder |
Try this :
function del($dir)
{
foreach(glob($dir . '/*') as $file)
{
if(is_dir($file))
del($file);
}
rmdir($dir);
}
It will also delete nested folders
|
Converting folder of XML files to folder of HTML files |
I think XQuery would be more convenient if you had all of your XML in a
database, but on the filesystem XSLT may be simpler.
I would just use Saxon-PE, and invoke it from a shell script. You could
also use Automator.
|
Iterate through spreadsheets in a folder and collect a value from each |
Its possible to pull that value youre interested in without opening each
workbook. Its much more efficient and reliable.
This code iterates through all files in the path variable and pulls values
without opening the Excel files. It then prints the values starting at F20.
You can then make another wrapper function to sum them up and delete or
whatever you want. Hope this helps
Private Sub CommandButton2_Click()
Dim tool As String
tool = CStr(Sheets("Sheet1").range("B9").Value)
Dim path As String
path = "T:EngineeringToolingTooling Control EngineeringPress Tool
Inspection Records" & strToolNumber & ""
Dim fname
fname = Dir(CStr(path)) ' gets the filename of each file in each folder
Do While fname <> ""
If fname <> ThisWorkbook.Name
|
How can I split a folder with thousands of images into multiple sub-folders? |
awk one-liner can do that. Consider this awk command:
find . -name "*.JPG" | awk '!(++cnt%100) {"mkdir sub_" ++d|getline}'
Run it inside the folder with 5000 images. This will create 50 folders with
the names sub_1, sub_2...sub_50.
Also to move files into these newly created directories:
find . -type f | awk '{
a[++cnt] = $0
}
cnt==100 {
subd = "sub_" ++d;
system("mkdir " subd);
for (f in a)
system("mv " a[f] " " subd);
cnt=0
}'
|
why my jsp 's compiled files i.e java files n class files are not visible in work folder |
You can find where the class resides (inside a jar or whatever), via:
<!-- This classes URL:
<%= getClass().getProtectionDomain().getCodeSource()
.getLocation().toExternalForm(); %>
-->
The getLocation delivers an URL.
|
How to Iterate a Registry Folder using Batch Script? |
reg query "HKLMSoftwareMicrosoftWindowsCurrentVersionInstallerFolders"|find
/i "Office14" >nul 2>&1 && set "RESULT=FOUND"
echo %RESULT%
appended after the question is answered:
target string is:
C:Program FilesMicrosoft OfficeOffice14 REG_SZ
getting the path name here is a bit difficult because of trailing
spaces/tabs. I suggest a solution with sed for Windows:
for /f "delims=" %%a in ('reg query
"HKLMSoftwareMicrosoftWindowsCurrentVersionInstallerFolders"^|sed -nr
"/\Office14\/Is/s+(.*)s+REG_SZ/1/p"') do SET "OFFICEPATH=%%~a"
echo %OFFICEPATH%
And a more advanced solution without sed:
@ECHO OFF &SETLOCAL
for /f "tokens=*" %%a in ('reg query
"HKLMSoftwareMicrosoftWindowsCurrentVersionInstallerFolders"^|find /i
"Office14"') do SET "OFFICEPATH=%%
|
Create the same multiple folder in all sub directory folders from excel list using VBA |
Use an array for the subfolders and loop through that for each of your 1st
level folders.
Change this line
vSubfolders = Array("A", "B", "C")
to add/remove your second level folders
Sub MakeFolders()
Dim xdir As String
Dim fso As Object
Dim lstrow As Long
Dim i As Long
Dim vSubfolders
Dim vSubFolder
vSubfolders = Array("A", "B", "C")
Set fso = CreateObject("Scripting.FileSystemObject")
lstrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
For i = 1 To lstrow
xdir = "C:UsersNikkiSharedVIC" & Range("A" & i).Value
If Not fso.FolderExists(xdir) Then
fso.CreateFolder (xdir)
End If
For Each vSubFolder In vSubfolders
If Not fso.FolderExists(xdir & "" & vSubFolder) Then
fso.CreateFolder (xdir & "" & vSubFolder)
End If
Ne
|
Batch Renaming Folders in AppleScript, Will Only Change Names of Every Other Folder |
Jart, the main issue was with the second loop, you need to be looping
through every folder of the x folder variable instead. It appears that
looping through the folder worked, but when you renamed them it caused an
index issue resulting in only reading every 2nd folder.
Here is a little reworking.
renamed your variables from y and x to be less cryptic.
changed the length test to support names > 9.
i was unsure about the item at the end of the new name, and if it should be
an incremented number instead. (you can easily revert)
left in some log calls for your reference, these can help debug stuff
tell application "Finder"
-- Defining Pro Folders
set pro_folder to folder POSIX file "/Users/Jart/Desktop/test"
set all_pro_folders to every folder of pro_folder
-- Iter
|
Randomly select 20 folders out of 50 in php, and then enumerate (thumbs) folder in each for thumbnails |
First, save all galleries in an array.
$storage = glob($galdir . '*', GLOB_ONLYDIR);
Now, shuffle the array.
shuffle($storage);
You now have an array with all your galleries randomly sorted. Loop through
them again.
for($i = 0; $i < 20; $i++) { //Only 20
echo $storage[$i]; //Directory name. Add your HTML stuff here
}
|
needing to iterate through a folder and store documents into a variable |
Generally speaking, your request is not practical because a variable can
hold at most 8191 characters. It would not take that many files to exceed
the capacity of a variable.
But if you know the number of files is relatively small, and the file name
lengths are not particularly large, then the following will work most of
the time.
@echo off
setlocal enableDelayedExpansion
set "loc=,"
for %%F in (*) do (set loc=!loc!"%%F",)
set "loc=!loc:~1,-1!"
echo !loc!
The above fails in the rare cases where a file name contains ! because
delayed expansion corrupts the value of %%F when it contains !.
The fix is to start out with delayed expansion off, and then toggle it on
and off within the loop. An extra FOR /F loop is used to transport the
value of !loc! accross the ENDLOCAL barrier.
@echo off
|
Copying files from one folder to another & rename at destination folder using shell scripting |
Write this script:
#!/bin/sh
for f in $1/*; do
read -p "New name for $f:" g
scp $f $2/$g
done
And then on the command line:
./my-script.sh folder-a folder-b
|
Rename files recursively by adding them the folder's name and move them into another folder |
This is a little bit tricky on windows ;)
But you can do it the following way:
create 2 batch files outside the folder which should be "scanned"
first one should be named findfiles.bat
forfiles /p %1 /s /c "cmd /c if @isdir==FALSE %~p0
enameit.bat @relpath
@file %1 %~p0"
the second one should be named renameit.bat
@echo off
set oldname=%1
set oldname=%oldname:.=%
set oldname=%oldname:"=%
set tmpname=%2
set newname=%oldname:=_%
set newname=%newname:"=%
move "%4%3\%oldname%" "%4%3\%newname%"
now you can execute the findfiles.bat with the main folder as parameter.
(so in your example : Pictures)
So for example if your Pictures folder resides in D: then create the 2
batch files in D:
then go to cmd and execute findfiles.bat Pictures
But be careful! Try to execute this on a copy of y
|
how can I copy the files in path.txt to new folder with same folder structure? |
You dont't need to read a list from a file. You could simply try this in
command prompt:
xcopy "full path to your folder" "full path destination folder" /e
Below is what you get if you type xcopy /? in command prompt:
Copies files and directory trees.
XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
[/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T]
[/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
[/EXCLUDE:file1[+file2][+file3]...]
source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
/A Copies only files with the archive attribute set,
doesn't change the attribute.
/M Copies only files with the arc
|
c# copying files from source folder to target folder |
You can check for each file if it exists this way:
string curFile = @"c: emp est.txt";
Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not
exist.");
put this inside your loop. then copy those files there.
MSDN CODE:
// Simple synchronous file copy operations with no user interface.
// To run this sample, first create the following directories and files:
// C:UsersPublicTestFolder
// C:UsersPublicTestFolder est.txt
// C:UsersPublicTestFolderSubDir est.txt
public class SimpleFileCopy
{
static void Main()
{
string fileName = "test.txt";
string sourcePath = @"C:UsersPublicTestFolder";
string targetPath = @"C:UsersPublicTestFolderSubDir";
// Use Path class to manipulate file and directory paths.
string sourceFile
|
Move all files and Subdirectories from a folder to another Subdirectory of the same folder |
This is gonna be very simple.
Directory.Move("SourcePath", "DestinationPath");
Process all directories in the source folder and use the above syntax for
each and every folder using forloop or foreach to move to your destination
folder.
|
How to include multiple class files and .Jar files in class path which exist in sub folders in linux? |
Use below command:
export CLASSPATH="$CLASSPATH:xyz.jar**:**path_to_abc.jar.jar"
You basically have to append to the classpath, all the new entries that you
want. To do so, just make use of ':' in linux and ';' in windows.
|
Google Drive - Change owner on folder, sub-folders and content, while saving tree structure |
Sorry this answer is late but I figure the answer would be helpful either
way.
1) Apps Script doesn't have the ability to suppress the notification email
but Google's most recent version of the Drive SDK does allow for this. You
just need to append "?sendNotificationEmails=false" to the url that you're
sending your request to. You can run a test on the linked page to see
exactly what the query string looks like.
2) The folders actually do maintain their structure. There is just the
consequence of a user getting ownership of each of those folders
explicitly. Since the rights are given one folder at a time, the user gets
access one folder at a time so they show up individually in the user's
Drive documents. Still, a Drive file/folder's sharing is stored separately
from its parent folder me
|
Batch Script to find Folder Length of 2 alpha-numerics only and delete thos folders |
this will delete all empty folders with two characters or less:
for /f %%i in ('dir /b /ad ??') do rd %%i
If you want also not-empty folders to be deleted:
for /f %%i in ('dir /b /ad ??') do rd %%i /s /q
If you use it not within a batchfile but as a single command, replace every
%%i with %i
EDIT (exclude a folder):
for /f %%i in ('dir /b /ad ??') do ( if "%%i" neq "FP" rd %%i /s /q )
|
How to add all new folders and files to Git? |
Keep in mind that you cannot add folders under revision. The only thing you
can add to git is content.
If you want to add empty folders. Add empty files in them and add them to
git however you want.
One trick to add everything you want is to use the interactive mode of git.
git add -i
if you press numbers, you can switch from one menu to the other
2) Add changes
3) Revert changes
4) Untracked files
5) Patch
I suggest to explore this command.
When you are in a menu, enter the number of the file in the list.
Ranges are also accepted. like 1-10 will select files from 1 to 10.
-5-7 will unselect files from 5 to 7
Also if some files aren't visible in the lists, but should be visible check
that you don't have a gitignore file somewhere that hides them.
|
files with same name in different folders |
Try this to get the files which have names in common:
cd dir1
find . -type f | sort > /tmp/dir1.txt
cd dir2
find . -type f | sort > /tmp/dir2.txt
comm -12 /tmp/dir1.txt /tmp/dir2.txt
Then use a loop to do whatever you need:
for filename in "$(comm -12 /tmp/dir1.txt /tmp/dir2.txt)"; do
cat "dir1/$filename"
cat "dir2/$filename"
done
|
How to concatenate files from different folders |
Depending on your shell, this might work : cat
{folder1,folder2,folder3}/output_*.txt.
It uses brace expansion which is implemented in :
Bash
Zsh
|
Ignore files and consider only sub-folders |
As to your first question, bizarrely enough
for d in ./*/; do echo $d; done
only gave me directories, even in /bin/sh. That sounds altogether too
straightforward to be correct, though. Alternatively, you may try
find . -type d -maxdepth 1
(find type directory, only one level deep), which will include hidden
directories and . itself.
|
folders downloading as files in ftp |
The FTP methods don't support downloading of folders, or recursion, by
themselves, so there's no other way I can think of doing this but what I've
suggested below.
Change the method so you can differentiate between files and directories
and handle them accordingly.
Change $ftprequest.Method =
[System.Net.WebRequestMethods+Ftp]::ListDirectory to $ftprequest.Method =
[System.Net.WebRequestMethods+Ftp]::ListDirectoryDetails
Which will list in this format:
-rwxrwxrwx 1 owner group 277632 Mar 4 17:15
xml_socket.log.rar
Directories will have a d in place of the - at the start of the line.
Here is an amended try block that will match only files so you can pass to
the downloadFtp function:
try
{
if(!($filename -match '^d')){if((Test-Path
("C:emsdropbox"+$filename.Spl
|