I wrote a program in python that created folders. I'm having difficulty removing some of the folders due to this glitch.
I already figured out how to prevent it. But for the folders already created are irremovable. I get this error message when trying to delete them.
Could not find this item. This is no longer located at ... Verify the items location and try again [Try Again][Cancel]
I tried removing the folders by typing dir /x into a console
and then using the shorthand of the folder name with the del program. ex: del FOLDER~1
But that only works some of the time.
The only difference between the broken and non broken folders is the space at the end of the folder name when creating.
How to make a broken directory:
mkdir "broken folder /"
How to make a normal directory
mkdir "normal folder/"
Extra info:
The folders can still be used. The files inside can be deleted. Just not the folder itself or its parent folder.
When this glitch occurs in python using os.mkdir it also creates two directories with the exact same name. Only one can be deleted regularly.
I wrote a python script that fixes all the broken folders. So if anyone hits this issue. Hope this helps. Just drop into whatever folder is full of broken folders. Its kind of poorly made. But gives an idea about what you need to do.
from glob2 import glob
import os
import shutil
#find all folders
folders = glob("./**/")
# for each folder check if they exist and rename them to have an A at the end of their name.
for fold in folders:
if fold != ".\\":
if os.path.exists(fold):
name = fold.rsplit("\\", 2)[-2] + "A"
print(name)
print(fold)
os.rename(fold, name)
Related
Essentially what I am looking to create is a script that will rename files in a folder, create a new folder with a specific name and place the renamed file in that new folder.
So, for instance, let's say that I had 2 files called:
test-spa.txt
test-ger.txt
I would then want to create 2 folders called spa and ger, respectively, place the appropriate file into each folder then rename the file by removing the language component; the resulting files in each folder would be test.txt.
Thanks,
Jaime
So here is the simple solution I came up with to create folders and place specific files in them. So long as I have the bat file in the same folder it works great:
#echo off
md spa ger
move file.txt EN\file.txt
move file-spa.txt spa\file.txt
move file-ger.txt ger\file.txt
I'm wondering if there is something missing that may cause an issue, such as specifying that this should only work in the current directory?
I am using rake to copy files I receive from one folder to two sub-folders.
After the copy I try to delete these files from their original folder.
I can't seem to delete some of the files (usually only 1 or 2 out of 5 or so).
When using mv (and not CLEAN) I receive an error message of access denied.
I believe that Windows (my OS) still holds a reference to the file/s and therefore won't
allow me to delete them.
I can delete the files out of code no problem. There should not be a permissions issue.
If my theory is correct that there is still a reference open to the file, then how could i close those references?
Could it be something else?
The code:
DOCK = '/path'
NEW_FILES = DOCK + '/NewFiles'
dock_stock = FileList.new(DOCK + '/*.xml')
file target_path do |t|
unless dock_stock.empty?
mkdir t.name
dock_stock.each do |f|
target_new_files_folder = f.pathmap(NEW_FILES + '/%f')
mv f, target_new_files_folder
end
end
end
Also it should be noted this task is a dependency to a multitask(really a dependency of a dependency of a dependency). task :clean => target_path being one of them.
So maybe the issue is multi thread related or the :clean task.
It seems there was a McAfee Agent that was referencing the files not allowing me to delete them.
For the most part, if I tried to delete them later on in time they would delete.
When I write for the most part I mean once in a blue moon it could hold the files for days until released manually.
The workaround would be to record the problematic files and exclude them from the file list and try to erase them at a later point.
Wish I had a better solution.
The windows del command has f option, which forces the deletion. Combine with /q(uite) and run it from Ruby with for instanceexec:
exec 'del /f /q filename'
I have a bunch of files I'm trying to organize quickly, and I had two questions about how to do that. I really appreciate any help! I tried searching but couldn't find anything on these specific commands for OSX.
First, I have about 100 folders in a directory - I'd like to place an folder in each one of those folders.
For example, I have
Cars/Mercedes/<br>
Cars/BMW/<br>
Cars/Audi/<br>
Cars/Jeep/<br>
Cars/Tesla/
Is there a way I can create a folder inside each of those named "Pricing" in one command, i.e. ->
Cars/Mercedes/Pricing <br>
Cars/BMW/Pricing<br>
Cars/Audi/Pricing<br>
Cars/Jeep/Pricing<br>
Cars/Tesla/Pricing
My second question is a little tougher to explain. In each of these folders, I'd like move certain files into these newly created folders (above) in the subdirectory.
Each file has a slightly different filename but contains the same string of letters - for example, in each of the above folders, I might have
Cars/Mercedes/payment123.html
Cars/BMW/payment432.html
Cars/Audi/payment999.html
Cars/Jeep/payment283.html
Is there a way to search each subdirectory for a file containing the string "payment" and move that file into a subfolder in that subdirecotry - i.e. into the hypothetical "Pricing" folders we just created above with one command for all the subdirectories in Cars?
Thanks so much~! help with either of these would be invaluable.
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 be moved. The fourth line simply marks the end of the loop.
If you are typing this directly into the command line, you can combine it into a single line:
for DIR in Cars/*/ ; do mkdir "${DIR}Pricing"; mv "${DIR}payment*.html" "${DIR}Pricing/"; done
A Day with Winrar
All I wanted to do was exclude folders and their contents using wildcards, and even after reading the docs, it turned into a guessing game...
So my test bed looks like:
C:\!tmp1\f1
C:\!tmp1\f1\f1.txt
C:\!tmp1\f1\a
C:\!tmp1\f1\a\a.txt
C:\!tmp1\f2
C:\!tmp1\f2\f2.txt
C:\!tmp1\f2\a
C:\!tmp1\f2\a\a.txt
And I am executing:
C:\>"c:\program files\winrar\winrar.exe" a -r !tmp1.rar !tmp1
which gives me a rar with !tmp1 as the root (sole top level folder).
The exclude switch is -x<filepathpattern> and may be included multiple times.
So, given that we want to exclude f2, and all its subcontents...
-x*\f2\*
removes the contents, but leaves f2
-xf2
does nothing - includes all
-x\f2
does nothing - includes all
-x*\f2
does nothing - includes all (now I'm mad), so surely it must be..
-x\f2\
nope, does nothing - includes all. So it has GOT to be...
-x*\f2\
hell no, does nothing - includes all. and I already know that
-x*\f2\*
removes the contents, but leaves f2. Onward we go...
-x*f2\
does nothing - includes all. Grrrr. Aha! how about...
-x!tmp1\f2\
nope, does nothing - includes all. WTF. Alright, So it has GOT to be...
-x!tmp1\f2
Holy moly, it worked! Hmmm, then how come....
-x*\f2
does not work? This was the little demon that sent me down this crazed path to begin with and should have worked!
Given all that, do I dare try to go after */a/* directories, removing contents and the dirs?
-x*\a
does not work, of course, does nothing.
-x*\*\a
does not work, of course, does nothing.
-x!tmp1\*\a
nope. But...
-x*\a\*
removes contents of both dirs, but leaves the folders. So, in desperation I can use the -ed switch which will not store empty folders, but this is a broad hack, I want to eliminate the folders specified not all empty folders.
With my animosity growing toward winrar, I am passing the baton of information forward with an eye to that glorious day when we will know how to specifically exclude a folder and its contents using wildcards and not using the -ed switch.
(Quite old question but still may be relevant)
Maybe what you simply needed was this :
-x*\f2 -x*\f2\*
two exclude switches, should remove directory f2 and all its contents.
An even older question by now, but came across this question so I reproduced your folder structure and, at least nowadays (Winrar 5.11, not the latest but quite new), this works:
-x*\f2
So the whole command line is:
"C:\Program Files\WinRAR\Rar.exe" a -m5 -s !tmp1.rar !tmp1 -x*\f2
And this is what is stored in the .rar file:
!tmp1\f1\a\a.txt
!tmp1\f1\f1.txt
!tmp1\f1\a
!tmp1\f1
!tmp1
Similarly, if you use -x*\a, all a folders are excluded, storing this:
!tmp1\f1\f1.txt
!tmp1\f2\f2.txt
!tmp1\f1
!tmp1\f2
!tmp1
Finally, combining both parameters (-x*\f2 -x*\a), you get this:
!tmp1\f1\f1.txt
!tmp1\f1
!tmp1
To manage large list of files to be excluded, you can create text fie and write all excluded files/folders relative to the source folder:
1) create file list.txt, write the name of excluded files/folders
note: * refer to the source, all files/folders are relative to the source folder
*\f2
*\f3
2) Run the command
rar a -r -x#list.txt target.rar source-folder
But it's there.
any ideas?
It happens when I am trying to get metadata from an image file (this is AppleScript running a shell script):
on getMetaData(filePath)
-->get meta data
try
set myCommand to (quoted form of (POSIX path of (pathToExifTool)) & " " & quoted form of (POSIX path of (filePath)))
set thisMetaData to (do shell script myCommand)
on error errMsg
log "Can't find exiftool:" & errMsg
end try
...
pathToExifTool is this:
/Users/steve/Desktop/XCodeApps/ImageArchiveDeluxeX/build/Release/ImageArchiveDeluxeX.app/Contents/Resources/exiftool"
and exists.
Here's the complete error thrown:
"Can't find exiftool:Can't locate Image/ExifTool.pm in #INC (#INC contains: /Users/steve/Desktop/XCodeApps/ImageArchiveDeluxeX/build/Release/ImageArchiveDeluxeX.app/Contents/Resources/lib /Library/Perl/Updates/5.8.8 /System/Library/Perl/5.8.8/darwin-thread-multi-2level /System/Library/Perl/5.8.8 /Library/Perl/5.8.8/darwin-thread-multi-2level /Library/Perl/5.8.8 /Library/Perl /Network/Library/Perl/5.8.8/darwin-thread-multi-2level /Network/Library/Perl/5.8.8 /Network/Library/Perl /System/Library/Perl/Extras/5.8.8/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.8 /Library/Perl/5.8.6 /Library/Perl/5.8.1 .) at /Users/steve/Desktop/XCodeApps/ImageArchiveDeluxeX/build/Release/ImageArchiveDeluxeX.app/Contents/Resources/exiftool line 30.
BEGIN failed--compilation aborted at /Users/steve/Desktop/XCodeApps/ImageArchiveDeluxeX/build/Release/ImageArchiveDeluxeX.app/Contents/Resources/exiftool line 30."
Well the bundle is a mess (lots of .pm files floating about - they look to be duplicates) but the exiftool-->image-->ExifTool.pm path is there.
====================================
Here's the solution h/t to Sherm
Apparently my directory structure went all to hell for some reason, either I did it unknowingly or something with XCode as Sherm indicated decided to wreck havoc. Anyway, (bear with my incredibly non-technical description) when working in XCode, yellow folders (or groups as they call them for some odd reason) will not be added to your bundle...hence exiftool (if you look at the first image) had no hierarchy to find its needed files, as evidenced by the bundle screen capture. I basically trashed all the related exiftool files from the app (right click/delete/delete references) and then brought them back in from the finder. You'll note in the third screen cap those directories are now blue. These will be built with the app.
Have you looked inside your app bundle's Resources/ dir to verify that the directory structure is maintained when you copy these files? IIRC, that doesn't happen automatically; the default behavior is to "flatten" resources, ignoring Xcode groups and simply copying all resource files into the top-level Resources/ directory.
You can avoid the default behavior by removing those groups & file references from your Xcode project - don't delete the files of course! Then, re-add the "lib" directory, taking care to choose the "Create Folder References" option.